Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aikoven/typescript-fsa-redux-saga
TypeScript FSA utilities for redux-saga
https://github.com/aikoven/typescript-fsa-redux-saga
Last synced: 2 months ago
JSON representation
TypeScript FSA utilities for redux-saga
- Host: GitHub
- URL: https://github.com/aikoven/typescript-fsa-redux-saga
- Owner: aikoven
- License: mit
- Created: 2017-03-03T15:10:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-08-11T04:02:38.000Z (over 3 years ago)
- Last Synced: 2024-10-11T00:08:45.426Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 69.3 KB
- Stars: 61
- Watchers: 4
- Forks: 4
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# [TypeScript FSA](https://github.com/aikoven/typescript-fsa) utilities for redux-saga [![npm version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]
## Installation
```
npm install --save typescript-fsa-redux-saga
```## API
### `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.#### Options
* `skipStartedAction`: Set to `true` if you want to use `started` action as a
trigger instead of an event. This is useful when using
`takeLatest`/`takeEvery` and you want to avoid having to manually dispatch an
extra trigger action. This way, you only have to manually dispatch an
`started` action, and saga will dispatch `done`/`failed` upon finish.**Example:**
```ts
// 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'});
}
```[npm-image]: https://badge.fury.io/js/typescript-fsa-redux-saga.svg
[npm-url]: https://badge.fury.io/js/typescript-fsa-redux-saga
[travis-image]: https://travis-ci.org/aikoven/typescript-fsa-redux-saga.svg?branch=master
[travis-url]: https://travis-ci.org/aikoven/typescript-fsa-redux-saga