Package Exports
- store-saga
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (store-saga) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
store-saga
An Rx implementation of redux-saga for ngrx/store
Usage
store-saga depends on @ngrx/store and Angular 2. After configuring @ngrx/store, install store-saga:
npm install store-saga --saveWrite a saga:
import {Saga} from 'store-saga';
export const Increment: Saga = iterable => iterable
.filter(({ state, action }) => action.type === 'DECREMENT')
.map(() => ({ type: 'INCREMENT' }));Bootstrap your app using the saga middleware provider and your saga:
import sagaMiddlewareProvider, { useSaga } from 'store-saga';
bootstrap(App, [
provideStore(reducer, initialState),
sagaMiddlewareProvider,
useSaga(increment)
]);Saga Factories
To run your saga in the context of the injector, you can write saga factories instead:
import {Saga} from 'store-saga';
import {Http} from 'angular2/http';
export function authenticate(http: Http): Saga<State>{
return iterable => iterable
.filter(({ action }) => action.type === 'GET_USER')
.flatMap(() => http.get('/user'))
.map(res => res.json())
.map(user => ({ type: 'USER_RETRIEVED', user }));
}Then create a provider for the saga with useSagaFactory:
import {useSagaFactory} from 'store-saga';
bootstrap(App, [
useSagaFactory(authenticate, [ Http ])
])