Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/biko2/typescript-fsa-redux-saga-extended
TypeScript FSA utilities for redux-saga used by BIKO
https://github.com/biko2/typescript-fsa-redux-saga-extended
Last synced: 29 days ago
JSON representation
TypeScript FSA utilities for redux-saga used by BIKO
- Host: GitHub
- URL: https://github.com/biko2/typescript-fsa-redux-saga-extended
- Owner: biko2
- License: mit
- Created: 2018-02-12T12:57:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-15T19:35:18.000Z (over 2 years ago)
- Last Synced: 2024-09-28T11:23:45.581Z (about 1 month ago)
- Language: TypeScript
- Size: 41 KB
- Stars: 7
- Watchers: 8
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# [TypeScript FSA](https://github.com/biko2/typescript-fsa-redux-saga-extended) utilities for redux-saga
## Installation
```
npm install --save typescript-fsa-redux-saga-extended
```## API
### `bindAsyncAction(actionCreators: AsyncActionCreators): HigherOrderSaga`
Creates higher-order-saga that wraps target saga with async actions, mainly based on [typescript-fsa-redux-saga](https://www.npmjs.com/package/typescript-fsa-redux-saga).
Main differences with[typescript-fsa-redux-saga](https://www.npmjs.com/package/typescript-fsa-redux-saga):
* It is designed to work with `takeLatest/takeEvery`
* Accepts an action instead of a `{params}` object
* Does not throw any error (which would stop all sagas)
* Does not dispatch an `started` action. This avoids the need for a `trigger` action, because instead of having another dummy action just for triggering, you can use that `started` action as a trigger.
* Resulting saga dispatches only `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*(
action,
): SagaIterator {
const bar = yield call(fetchSomething, action.payload.foo);
return { bar };
});function* watchIncrementAsync() {
yield takeLatest(doSomethingWorkerActionCreator.started, doSomethingWorker);
}
```