-
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
Full state from the nested action (question) #712
Comments
@dmitrykurmanov You're right, you should try not to need global state in your nested actions. What does happen when you're using nested actions, is you sometimes want to call another action in another namespace (or in the "root" namespace). For that, I have a technique explained here: https://zaceno.github.io/hypercraft/post/cross-namespace-action-calling/ I think, with this technique, you shouldn't need access to the global state, because instead you can call actions in the global namespace from the nested actions. If you really want global state in a nested action, create an action in the global namespace like this:
Now you can use the technique described above to access
... but I hope you don't have to do that 😜 There must surely be a more clean and readable way to achieve what you need. |
Hi @dmitrykurmanov! Nope, there's no way to get the state from a nested action. Please consider @zaceno's advice in the meantime or until 2.0 is out. In 2.0 (#672 #696) actions are flat and unwired (they take the global state) and slices are no more, so this won't be a problem going forward. The new "problem" will be how to slice the state like we do in 1.0. This will be possible via an optional library. Cheers! |
Thank you guys for the answer! I just try to create some components with hyperapp and without nested actions my actions will be more complex, for example: // partial state = fullState.nodes
const node = state[id];
const isExpand = !node.isExpand;
return {
...state,
[id]: {
...node,
isExpand
}
}; and without: // fullState
const node = state.nodes[id];
const isExpand = !node.isExpand;
return {
...state,
nodes: {
...state.nodes,
[id]: {
...node,
isExpand
}
}
}; It is not the big problem in fact :) Anyway if in ha2.0 the problem will gone it is ok for me. And I think that you should not be distracted by this. |
@dmitrykurmanov Slicing the state in 2.0 will be possible via an external library. It will not be exactly the same as 1.0, but I'm more excited about it being optional than introducing more features to the framework. |
@jorgebucaran sounds great! |
Do we plan to provide that library or will that be on the community to provide? |
Hello! Thanks for the project. I think it is great!
Is there way to get the full state (global) from nested actions ?
May be I should use nested actions only if I want totaly isolated part of my hyper app.
Could anyone tell about best practicies?
The text was updated successfully, but these errors were encountered: