Very interesting, and I can see the validation benefits.

First of all, thanks for the questions and I’m sorry for the confusion. I eventually want to put together a longer post focussing more on refactoring existing reducers to use FSFs, so keep your eyes peeled for that. With this post, I wanted to focus more on introducing the high-level API.

The original example actually comes from the example Todo project: The example reducer also has a function for toggling the “completed” value. I didn’t include that second reducer in any of the examples, hence why it seems that “completed” is always false.

As far as default values go, you’re right, I think that is a gap in the current functionality. I typically set default values in the action creator. Business logic is generally codified in the action creators and default values could be considered business logic. But that’s just what I do; many solutions would be correct.

If this library was to provide functionality for defining default values, I think I would add them to the define() function. It’s an idea that I have tossed around a bit, but haven’t spent much time fleshing out. If you have anything specific in mind or would like to see that added, feel free to open up an issue on the GitHub repo.

One last thing: I generally like to keep my reducers “idempotent.” In other words for any given state, if the same exact action is dispatched one or more times, the resulting state will always be the same. Reducing functions like “toggle,” “increment,” and “decrement” break away from that pattern. The same action can be dispatched repeatedly yet the store would continuously change. One subtle opinion of FSFs is that the favor idempotent reducing functions. For example, the “toggle” reducer would likely be written either as two separate “complete” and “uncomplete” functions or as a “setState” function that takes an “isCompleted” parameter.

Again, thanks for your interest. I hope I answered your questions. Please feel free to reach out here or on GitHub if you have any other questions! 😊