redux-mediator
Redux middleware to support mediator pattern. Helps you to reduce complexity of large redux applications by separating your codebase into independent modules which know nothing about each other. Communication between modules is encapsulated within a mediator middleware. Modules no longer use actions of each other directly, but instead communicate through the mediator. Mediator maps output actions of one module to input actions of another. This reduces the dependencies between communicating objects, thereby reducing coupling.
Install
npm install redux-mediator --save
Usage
The default export is a function - creator of middleware. It accepts one Object parameter - action mapper. Keys of this object is action types, values - descriptors of action transformation.
Transformation descriptor fields:
type
[any] - type of mapped action (required*);create
[function] - action creator (required*);predicate
[function] - predicate to check if action should be mapped (optional).suppress
[boolean] - flag, which indicates if initial action should be suppressed (optional).
* user have to specify one of type
or create
. If create
is specified, then type
will be ignored.
Action creator:
- action - initial action;
- state - current redux state (result of
store.getState()
call).
Predicate:
- action - initial action;
- state - current redux state (result of
store.getState()
call).
Example:
; const mediator = ;
Changelog
version 1.1.1:
- fixed the order of dispatching
version 1.1.0:
- added support for multi descriptors
version 1.0.1:
- first stable version
License
MIT