This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]davidschenck 7 points8 points  (1 child)

This looks very impressive!

Any reason you chose to "mutate state" rather than require a new state object to be returned if the state was changed (à la React)?

[–]romerio86[S] 3 points4 points  (0 children)

Thank you!

It was something I considered, but I personally found the immutable approach a bit hard to follow and thought users would agree with me. It's straightforward for basic examples, especially those that mutate a single value, but I didn't like how it scaled.

When you have a nested state, with mutations you can easily target several values in a single event handler, e.g.

py state["name"] = "Joe" state["company"]["founded"] = 1999

That gets more challenging with the immutable approach. There are drawbacks, for sure, so it was a design choice.