Feature Request
stateGen looks like the beginnings of something like Redux.
Would it be possible/are you planning to extend stateGen to support more of the Redux pieces like the reducers and maybe middleware too? Something reducer like would be incredibly handy.
@nathanhack - sorry for the slow reply.
Having never really used Redux I can't claim to being able to agree with your assertion or otherwise!
But maybe some background will give you the answer you need:
- we have a big frontend app that uses an immutable graph of data
- we use an RPC-like approach to modify that data graph, with deltas being sent to the frontend
- state is maintained separately and, for the purposes of this discussion, is entirely frontend (save the persistence)
- some components (e.g. dropdowns) maintain their own "private" state in order to function properly
- some components need to share state
- some such components share state by being passed props by a parent component
- other such components need to share state but are sufficiently disconnected as to make props passing ugly/near impossible
- we want to be able to persist some state
For points 7 and 8 we use a state tree generated by stateGen. Instead of passing values as props we instead pass references to nodes/leaves in the state tree.
These nodes/leaves support the concept of publishing updates when values beneath them change.
A good example of the generated state tree in use can be found in https://github.com/myitcv/react/blob/7cf02ba84fd89b1a37f7cb92e52600de6dc62b0f/examples/sites/globalstate/person_chooser.go. It uses the state tree whose template definition can be found in https://github.com/myitcv/react/blob/7cf02ba84fd89b1a37f7cb92e52600de6dc62b0f/examples/sites/globalstate/state/state.go.
One thing not currently supported by stateGen (but that does exist in our Typescript-world) is the ability to Transact(func ()) on the state tree (can be called from any node/leaf) - the function you pass in then gets called and for the duration of that callback notifications get queued and fired when the function returns. This should be trivial to add to stateGen.