-
Notifications
You must be signed in to change notification settings - Fork 780
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
Return the state fragment to the caller if the action is a reducer. #243
Conversation
Now actions.myAction will return whatever the original myAction function returns. Before, this was only true if myAction returned a Promise. Fix #242.
…at/actions-return-sub-state
Codecov Report
@@ Coverage Diff @@
## master #243 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 4 4
Lines 165 165
Branches 45 45
=====================================
Hits 165 165
Continue to review full report at Codecov.
|
🎉 💯 |
So does this still update the state or did you just implement my suggestion regarding getting rid of the weird return to update functionality? |
@dodekeract This returns the result of an action to the caller, whatever that may be. This just helps with @zaceno's use case without breaking the API. Maybe @zaceno can explain it better? |
@dodekeract: still updates state. I kind of still wish we could have getters, i.e. same as actions but dont update state -- just return out whatever the inner function returns from the state. ... thinking maybe you'd be more ok with the behavior of actions if there were getters to use for when you don't want the state to update? |
@zaceno Those are the old effects no? Maybe we can come up with another clever way? |
@jbucaran -- that's right! Hadn't thought of it before because I always thought of effects as a way of batching and/or deferring reducers -- not as a way of getting/processing data from the state -- but the old effects could work for that too. I'm open to thinking about & discussing clever ways to get that behavior back. But to be fair you shouldn't give my opinons on hyperapp's state management too much weight, since I've switched my personal projects from away from hyperapp, to picodom + my home made state management solution (which I'm still very much experimenting with) Anyhow, here are my thoughts: I feel like we've already "violated" the reducer principle when we allowed actions to return a promise, and in that case not update the state. So we could always take that a step further, with other "magical" ways of returning in actions, that don't cause state updates. Like perhaps if what you returned was an object I grant you, that's not very pretty. I'd much prefer something along the lines of what @dodekeract already suggested, which is that actions always return with the inner-returned value, and don't update state by default. Instead they are passed a |
@zaceno Thanks for the feedback! Definitely, something to think about. |
Not true. In complex actions I'm often using Now, this would update the state twice which may even lead to race conditions or hard to track down bugs. Actually, I just upgraded from |
@dodekeract I see what you are saying. I can try to give priority to #90 (leaving #238 for later) and see if that helps, otherwise, we can reverse this. |
Return the state fragment to the caller if the action is a reducer.
Now actions.myAction will return whatever the original myAction function returns. Before, this was only true if myAction returned a Promise.
Example
Diff: 0 bytes.
Fix #242.