A note on terminology: There are a lot of things with similar meanings/use-cases around: subscriptions, reactions, derived atoms, view models.
I'll introduce another to make things even worse: derivative. A derivative implements IWatchable
and it's value is the result of applying a function to the value of other things (sources) implementing IWatchable
. Whenever any of the sources change the value if the derivative is updated.
Let's assume you're hooked about the idea of storing all your application state in a single atom (db
). (Why this is a great idea is covered elsewhere.)
Most of your components don't need the entirety of this state and instead receive a small selection of it that is enough to allow the components to do their job. Now that data is not always a subtree (i.e. (get-in db ...)
) but might be a combination of various parts of your state. To transform the data in a way that it becomes useful for components you can use a function: `(f @