-
Notifications
You must be signed in to change notification settings - Fork 142
How to attach state to renderer? #218
Comments
I'm not sure exactly what your question is. Are you already running a mercury app that these components will be put inside? It looks like you want
|
@crabmusket
And now when I have in part_row component :
changeQuantity is triggered on event, it works, but it does not re render part_row. Here is repo: https://github.com/Tarvald/bom |
Hmm that doesn't look right - |
@crabmusket Sorry I'm quite new in FRP, mercury, states etc. |
So even I did In the render I had to do state.part_number() instead of just state.part_number |
Maybe I'm misremembering, and you can't nest |
Ok, so please take the following as a very subjective opinion: However this still was not quite good enough. So I went back and thought a lot about this, what is the best way to deal with state on the frontend when it becomes large and complicated, and since then I am using a mercury where I replaced the observ-* tree with https://github.com/typeetfunc/datascript-mori Now, this has it's own issues, mainly that writing datalog in js and using mori functions is still a pita, but at least now state is easy. It's in one place, it's fast, and I can ask anything from it with a cool query language. So writing new views although is very verbose and takes longer than it should, it also gives a very flat structure that's easy to understand and grasp once you know what's happening. Again, this fits my needs so far, when it doesn't, I tend to not use mercury but go for react/redux. |
What I did to compose trees of state is write a base component that binds the state to a render function. I have the module here, npm here. This allows me to have child components as part of the state tree, and call render on those child components directly without worrying about what their immediate render function is. |
See also this section of the FAQ. Here Raynos seems to use EDIT: oh hey. Back in my original comment I made a mistake. @Tarvald, maybe try this: export default (opts) => {
return hg.state({
parts_list: hg.array(opts.parts.map(part_row_state)),
})
} E.g. you need to convert the result of |
@crabmusket this kind of trial and error that I got bored with eventually and decided to read up on state management and ended up here: https://www.infoq.com/presentations/Value-Values :) |
I have part table component, this component will use part_row component so lets imagine:
Part_row component:
State:
Renderer:
Table component
State:
And finally renderer:
Sooooo how to "connect" or "attach" in this pattern part state? I don understand that. Why I should create state for part_row component if I pass state to renderer. The only stupid solution what I can imagine would be
Table component
State:
Thanks for help :)
Regards
The text was updated successfully, but these errors were encountered: