@redux-actionlang/sagas
v0.1.0-beta-10
Published
Quickly Create Sagas to transform your actions to other actions and more.
Downloads
16
Maintainers
Readme
@redux-actionlang/sagas
Quickly Create Sagas to transform your actions to other actions and more.
The Setup
import SagaGenerator from '@redux-actionlang/sagas';
import SagaMiddleware from 'redux-saga';
const SagaGenerator = new SagaGenerator();
createSagaMiddleware().run(SagaGenerator.create());
The Usage
filter operator
- Used to filter some actions so that you can apply map to filtered actions only.
- Every Action will still go through reducer.
SagaGenerator.filter(action => action.type === 'MY_TYPE');
map operator
- Apply a function on every action or every filtered action if filtered is used before.
SagaGenerator.map((action, { put }) => action);
every operator
- Used to filter a particular action so that you can apply map to that action only.
SagaGenerator.every('LOG').map(action => console.log(action));
mapState operator
- Injects state to your map chain.
SagaGenerator.every('LOG').mapState(state => action => console.log(state.list, action));
create
- Create a saga to be used in Saga Middleware.
SagaGenerator.create();
Examples
- A Simple Logger
Will log every action dispatched to the reducer.
SagaGenerator
.map(action => console.log(action))
.create();
- Dispatch an action in response to another action.
SagaGenerator
.filter(action => action.type === 'MY_TYPE')
.map((action, { put }) => put('YOUR_TYPE'))
.create();