A one of the features of FRP is the ability to take foreign events (inputs!) and write a function that takes application state & the event and returns new application state.
This is cool because you can it forces you to group and explicitely describe how your inputs effect your state. When combined with only having static inputs it makes your application code flow from input description to application state in a nice linear, readable fashion.
You can also group all these transforms near each and other and have a good oversight of what ACTUALLY changes your application state.
One example here uses plain Objects & Arrays as your data structure. It uses a utility extend as a bit of sugar to non-destructively shallow extend objects.
This is cool because it's simple. It's just objects and arrays and its immutable which fits nicely with the functional style.
The other example uses a thin Immutable data structure example. The benefits of this are that we can use a patch function that's a bit shorter. Especially for the modifyTodo
function.
The other benefit is that the implementation detail level we can use structural-sharing (red black trees) or mutable data structures for performance benefits. Another benefit is that you can efficiently track deltas because they are the arguments to patch
functions which aids greatly in delta based rendering.
- Are Objects / Arrays nicer because it has less abstraction overhead
- Are Immutable structures nicer because the API is simpler & it's more performant?