-
Notifications
You must be signed in to change notification settings - Fork 781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async actions appear to be out of order #367
Comments
load event is special, return from it is node, which is used for dom hydration. If you aren't hydrating from ssr/pre-render you shouldn't return from load. |
Oops, missed that looking through the docs. OK, if I get rid of the |
Since you're using promises, you may need to add this boilerplate described on https://github.com/hyperapp/hyperapp/blob/master/docs/events.md, in order to allow actions to return a Promise.
|
Same result ... which makes sense, if I understand the documentation right the |
OK, I figured it out. The key is something similar to what @andyrj said--instead of returning a call to update with the existing state from the TL;DR: avoid potential infinite loop by not calling the async |
How could we determine if the state changed or not? We could check if |
I'm trying to use async actions. For simplicity, I'm using only a single action, called
update
, and dispatching all app actions through that. I'm also using theload
andupdate
events to set a state value on app startup and print the value on every state change, respectively.Here's the code:
I'm having two problems:
State updates appear out of order. First
state
is{ model: 5 }
, then it's{ model: 0 }
, while my understanding is it should be the other way round.State seems to become
{ model: undefined }
after theload
event fires, so the view renders asCurrent value: undefined
, and clicking the Increment button logsObject { model: NaN }
.Any suggestions on fixing these async updates? Thanks
The text was updated successfully, but these errors were encountered: