4 ms·
With only one store, how do you keep your state reasonably organized when you get up to hundreds of pieces of data to manage? And what do you do about generic
by badfrog 8y ago
With only one store, how do you keep your state reasonably organized when you get up to hundreds of pieces of data to manage?
And what do you do about generic reusuable components that need state? Say a typeahead search that needs to track the input string and the list of results from the server?
- pault 8y agoYou can think of each root-level branch of the state tree as its own "model". In redux (I haven't used elm much) I implement generic components by finding a property that can be used to derive a unique key and creating an entry for each component in the reducer.
- danabrams 8y agoIf you really really really can’t live without a statefull component, you can always build a custom element (which can be a wrapper around an elm app). But reusable views with fairly complex state are used; they require a little bit of wiring up, but it means you know exactly where to look when there’s a big/problem.
- razze 8y agoYour state can be a tree, if it needs to be, so you can nest. A normal practice is to have a model per page. For e.g. https://github.com/rtfeldman/elm-spa-example/blob/master/src/Page/Home.elm#L31-L40 https://github.com/rtfeldman/elm-spa-example/blob/master/src... And you can have another item next to it for global state if you need to. https://github.com/ohanhi/elm-shared-state https://github.com/ohanhi/elm-shared-state explains one way to do this