I want to do something based on an action being dispatched, rather than the state being a given value. For example:
- Reload the timeline immediately after I log in on my Twitter client
- Retrieve data about a notification immediately on receiving a notification
I could set up a reactive signal or promise or something like that and pump events into it, and dispatch events into Redux. But I already have a place that I'm dispatching actions into: the Redux store.
It reminds me of Yaron Minsky's blog post with some discussion about edge-triggering vs level-triggering.
(waitForState
is a bit overengineered for this example, compared to waitForAction
)
I think the end result is the same, the semantics & expressed intent are different:
With the state/subscription
With the action
It's more natural/idiomatic in Redux to use #1, indeed, the library and surrounding documentation focus on Redux as a state container.
What I'm interested in is exploring the action dispatch mechanism as a first-class citizen in an application, rather than being relegated to "the way to (eventually) trigger a state change". To abuse Haskell-ish definitions (also stealing
Eff
from PureScript), conventionally:but store is a specialisation of "something that accepts actions and turns them into side-effects"
(I'm a bit of an FP novice, so this might not make much sense?)
To experiment, how about
redux-thunk
? Thunk is "something that takes a store and will eventually dispatch actions into that store"Er, I'm getting lost!