Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

But what’s the benefit of this approach? It seems needlessly expensive, both in terms of computational overhead (walking up and down the state tree) and how much more code it requires.

I guess you gain persistence of your entire app’s state (which makes time travel debugging easier) but that’s all I can think of.



In my experience when applying this architecture to react or svelte, the performance is quiet good, often better than classic alternative approaches (redux, many local useState)

But the main benefit is not only the persistence of the app state, but composable globally consistent state. With most state management solutions at some point you hit a wall where communicating state changes between far away components is really difficult. You need to manually manage eventlistener lifecycles, route events through the application and convert events into state changes and state changes into events, while not causing cycles or unstable feedback loops or race conditions.

With lenses the state tree is composed declaratively and locally. each component does not need to care if the parent state is locally constructed or coming from further away.

/edit: Actually using this approach you are not forced to have a single global state but instead each component can simply decide to embed its child components state into its own state or not. If all components decide to embed their children state you get a single global state. But if all components decide to not embed their children state you get only local state with no communication. But the unified Interface gives you the choice.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: