|
|
|
|
|
by daveidol
4173 days ago
|
|
One thing I would love to see some guidance on with Flux (and potentially with the patterns expressed in Marty.js) is how to handle the use case of Stores for a collection of items as well as a single item. Right now, if I create a Store for a collection of Users and I want to be able to mutate these User objects then I create actions for each CRUD mutation and then plumb that change through to the in-memory object inside my collection as well as persist the change to my server. But as soon as I click on a specific User and load up a new page for that User, for example, then I need to create an all new Store just for a single User, which has all of the same mutations/actions available to it as the previously-mentioned collection Store (except now I don't need to pass the ID to every action payload). The best approach I've seen on this topic is in this example's Readme: https://github.com/gaearon/flux-react-router-example Does this approach make sense/jive with the Marty.js way of handling Stores, State Sources, etc? |
|
Another way is to use a nested immutable data structure (something like immutable.js[1], react-cursor[2]), use only one store, and make all changes on this data structure and pass accordingly.
Even if you don't use immutable.js, I strongly suggest to use immutability with react update[3] or equivalent. Things get way easier that way.
[1]: https://github.com/facebook/immutable-js
[2]: https://github.com/dustingetz/react-cursor
[3]: https://facebook.github.io/react/docs/update.html