JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q23310F
  • License MIT

An Rx implementation of redux-saga for @ngrx/store

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 --save

Write 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 ])
])