
Babydux: Paper-thin, 100% typesafe Redux for babies - bcherny
https://github.com/bcherny/babydux
======
acemarke
I find the tagline to be rather confusing. Why "for babies"?

Also, while this appears to be _inspired_ by Redux, it's definitely not the
same as Redux. In particular, it has separate event emitters for each top-
level key in the state instead of a single change event, no middleware, no
store enhancers, etc.

~~~
bcherny
Thanks for the feedback. The "for babies" part came out of a conversation with
coworkers a while back, where people were complaining that Redux is too
complicated. Ie. To add a property to the store, you also have to define an
Action and a type for that Action, then add the type to your Actions sum or
enum type, then define a case for one of your reducers, and finally use the
property in your React component. I thought this could be simplified quite a
bit for the 90% use case where an action maps directly to a property on the
store.

Babydux is certainly a Redux. From the Readme:

> Babydux is like Redux, but reducers are already baked-in. Babydux
> automatically creates an action and a reducer for each key on your state, so
> you don't have to write tedious boilerplate. Babydux still emits Actions
> under the hood (which you can listen on to produce effects), but gives you
> an incredibly simple get/set API that covers most use cases.

There is an undocumented top-level emitter (`onAll`), but I'm not sure there
is a use case for it where targeted emitters wouldn't be a better fit.

There is certainly middleware support (see
[https://github.com/bcherny/babydux#effects](https://github.com/bcherny/babydux#effects)).
Unlike Redux, middleware fires _after_ the state has been updated, not before.
The effect is to fold the concepts of middleware and subscriptions into one. I
want to keep the API as simple as possible, but I could see a future where
before-write middleware could be a good fit for simulating transactions and
preventing writing bad state to the global store.

