Closed farskid closed 6 years ago
Thanks for that PR! Love it :) Going to merge it as soon as possible, but my left hand is damaged atm, so I should use the computer at all :/
@rofrischmann Thanks for the kind words :) Take care with the hand ;)
I just came across an issue as you transformed the setState call from (simplyfied):
this.setState(prevState => ({ state: actions[name](prevState, ...) }))
to:
this.setState({ state: actions[name](this.state.state, ...) })
because you have to precalculate the value in order to check for async functions, but here's the issue: Without the functional setState (that passes the prevState to the callback), we might miss state updates if setState is called simultaniously.
A possible fix would be to separate async stuff from actions, e.g. calling em effects
that get the setState
handler passed.
Is it the same issue with how React batches state updates asynchronously?
Do you have a test case for me to test something as a fix?
Yes, sadly it is. Apparently, there's no easy fix for this by returning Promises. I just added the effects
option and released under 3.0.0 as I had to move forward quickly to finish some private stuff. Feel free to enhance, comment or improve that one though.
I appreciate your efforts!
The change to support effects sounds cool! thanks for doing this 👍
Yeah it's a more general approach to side effects I guess. Doesn't necessarily require Promises at all.
Adds support for asynchronous actions which return a promise (then-able object).