Redux Remotes
Trigger side-effects (e.g. async actions) via dispatch. Vaguely similar to cerebral signals or elm side effects.
Remotes provides a standard, predicatable API for handling async actions. It is similar to using redux-thunk, except instead of dispatching a function, you dispatch a "command" action which is then handled by one or many remotes. There are potentially a few benefits to this approach:
- Serializable (as opposed to action creator invocation which is not)
- Robust and standardized logging
- Many side effects can be triggered by one action, or one side effect can be triggered by multiple actions
Additionally because the structure of remotes mirrors that of reducers, the mental model is light and easy to integrate within an existing redux application.
Not necessarily redux specific, but that is the target architecture.
What does it look like?
Remotes works as follows:
- Compose multiple
remotes
into a singleremote
function (just like you do with reducers - Install the middleware. The middleware sends every action to the registered remote before passing it along.
- A contract is created for every action that one more remotes handles.
- Each remote calls finish() when it is done operating on an action.
To get a better idea of what this looks like, see the console logging upon contract completion:
Usage
const remote = const remoteMW = const createStoreWithMiddleware = createStore
in reducers/someReducer.js
{ }
Use Cases
Restful Resource
{ { } { } { }}
Other times remotes may not need to report their status as actions. For example a remote action logger:
{ return true}
Or a remote stream
{
Uncertainties
This may need some tweaking to play well with store enhancers like redux-devtools. Further testing and experimentation is needed.