TypeScript FSA utilities for redux-saga
![Build Status](https://github.com/camo/3c4975603f7cb7be9b720644f060456edf1af06fbdfa0f5624212fbc8d7fa654/68747470733a2f2f7472617669732d63692e6f72672f61696b6f76656e2f747970657363726970742d6673612d72656475782d736167612e7376673f6272616e63683d6d6173746572)
npm install --save typescript-fsa-redux-saga
bindAsyncAction(actionCreators: AsyncActionCreators, options?: BindAsyncActionOptions): HigherOrderSaga
Creates higher-order-saga that wraps target saga with async actions.
Resulting saga dispatches started
action once started and done
/failed
upon finish.
skipStartedAction
: Set totrue
if you want to usestarted
action as a trigger instead of an event. This is useful when usingtakeLatest
/takeEvery
and you want to avoid having to manually dispatch an extra trigger action. This way, you only have to manually dispatch anstarted
action, and saga will dispatchdone
/failed
upon finish.
Example:
// actions.ts
import actionCreatorFactory from 'typescript-fsa';
const actionCreator = actionCreatorFactory();
// specify parameters and result shapes as generic type arguments
export const doSomething =
actionCreator.async<{foo: string}, // parameter type
{bar: number} // result type
>('DO_SOMETHING');
// saga.ts
import {SagaIterator} from 'redux-saga';
import {call} from 'redux-saga/effects';
import {doSomething} from './actions';
const doSomethingWorker = bindAsyncAction(doSomething)(
function* (params): SagaIterator {
// `params` type is `{foo: string}`
const bar = yield call(fetchSomething, params.foo);
return {bar};
},
);
function* mySaga(): SagaIterator {
yield call(doSomethingWorker, {foo: 'lol'});
}