Skip to content
This repository has been archived by the owner on Aug 27, 2018. It is now read-only.

Feature Request #108

Open
nathanhack opened this issue Feb 9, 2018 · 1 comment
Open

Feature Request #108

nathanhack opened this issue Feb 9, 2018 · 1 comment

Comments

@nathanhack
Copy link

nathanhack commented Feb 9, 2018

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.

@myitcv
Copy link
Owner

myitcv commented Apr 3, 2018

@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:

  1. we have a big frontend app that uses an immutable graph of data
  2. we use an RPC-like approach to modify that data graph, with deltas being sent to the frontend
  3. state is maintained separately and, for the purposes of this discussion, is entirely frontend (save the persistence)
  4. some components (e.g. dropdowns) maintain their own "private" state in order to function properly
  5. some components need to share state
  6. some such components share state by being passed props by a parent component
  7. other such components need to share state but are sufficiently disconnected as to make props passing ugly/near impossible
  8. 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants