Notice how the body is immediately under $jason, which means everything is server-side rendered and there is no $render action.
What happens in this case is:
Jasonette loads the initial markup and starts drawing it on the screen.
And while step 1 is still in progress, Jasonette triggers the $reload action because $show was triggered.
The result is Jasonette having to fetch exactly the same JSON from the server twice.
This results in very poor performance both client side and server side (You are making two duplicate requests consecutively, as well as trying to render the same duplicate markup consecutively while the initial drawing is going on)
I can understand why people use this approach--because they want the view to be fresh everytime it shows up--and currently there is no easy way to distinguish between the initial $show event (triggered right after $load) and subsequent $show events (triggered when coming back from child views).
The current approach
Here's how it currently works:
$load is triggered only once when a view loads for the first time
$show is triggered when a view gets "displayed", which includes the initial load as well as when coming back from other views.
The framework assumes that the user will only use either $show or $load (and not both).
The new approach
The new approach attempts to keep backwards compatibility while adding more flexibility. More specifically we're adding one more scenario (Handling when both $load and $show handlers exist)
When there's only a $show handler
$show: Handles both initial load and subsequent show events
When there's only a $load handler
$load: Handles Only the initial load event
When there are both $show and $load handlers
$load : handle initial load only
$show : handle subsequent show events only
Summary
$load:
triggered when view loads for the first time. (Same as before)
$show:
triggered at load time + subsequent show events (IF $load handler doesn't exist)
NOT triggered at load time BUT ONLY at subsequent show events (IF $load handler exists)
Related: https://github.com/Jasonette/JASONETTE-iOS/pull/232
Problem
I have noticed a frequent usage pattern where the current
$show
and$load
syntax cannot support easily.This happens in the following case:
$render
on load.$show
handler and doing a"type": "$reload"
, like this:Notice how the
body
is immediately under$jason
, which means everything is server-side rendered and there is no$render
action.What happens in this case is:
$reload
action because$show
was triggered.I can understand why people use this approach--because they want the view to be fresh everytime it shows up--and currently there is no easy way to distinguish between the initial
$show
event (triggered right after$load
) and subsequent$show
events (triggered when coming back from child views).The current approach
Here's how it currently works:
$load
is triggered only once when a view loads for the first time$show
is triggered when a view gets "displayed", which includes the initial load as well as when coming back from other views.$show
or$load
(and not both).The new approach
The new approach attempts to keep backwards compatibility while adding more flexibility. More specifically we're adding one more scenario (Handling when both
$load
and$show
handlers exist)When there's only a
$show
handlerWhen there's only a
$load
handlerWhen there are both
$show
and$load
handlersSummary
Here's a demo: https://jasonbase.com/things/o2Q5