4 ms·
Sure, that makes sense in a Redux app where you can use FP techniques as you see fit. How do you do that in something strictly functional like Elm? As I underst
by superice 3y ago
Sure, that makes sense in a Redux app where you can use FP techniques as you see fit. How do you do that in something strictly functional like Elm? As I understand it 'local state' or a component handling messages locally is not really a thing there.
- Akronymus 3y agoI am using elmish, which I think is similar enough: every component has its own update method and events it dispatches.The events get wrapped in every parent component until it gets to the root, there it gets unwrapped and passed to the appropiate child update method. At any point, you can intercept the event/update. (Each component consists of a view, a model and an update function, the model contains wrapped versions of the children models and dispatched updates get passed into the children updates)
- boris_m 3y agoWhat is the role of the "root node" in Elm?
- piaste 3y agoIt's the broadest level at which two elements can affect each other. Classic example: if you have a notification bubble near the top of the page, and a notification gets created by some component hidden deep inside the app structure, that message can't be handled in a local sub-model; it must travel all the way to the root node to update the notification bubble stack in the main model. (Which is why nowadays I prefer to skip the nesting and just have a flat list of all messages in the app. With good spacing and naming, it's quite maintainable and just as solid.)
- rq1 3y agoJust imagine your root function as: F(f_1(x_1), f_2(x_2), …, f_n(x_n)) The root function is a collection of projections acting on (x_1, x_2, …). And the components receive the right set of coordinates to act on. I’m not sure if it’s clearer that way though.