Creates a saga in the context of the injector.
Params
factory
SagaFactory Factory function called in the context of the injector. Must return a function that implements theSaga
interface.dependencies
any[] Array of dependencies the factory function needs
Returns Provider
const authEffect = createSaga(function(http: Http) {
return saga$ => saga$
.filter(saga => saga.action.type === 'AUTH')
.map(saga => saga.action.payload)
.flatMap(payload => {
return http.post('/auth', JSON.stringify(payload))
.map(res => {
return {
type: 'AUTH_SUCESS',
payload: res.json()
}
})
.catch(error => Observable.of({
type: 'AUTH_FAILED',
payload: error.json()
}));
});
}, [ Http ]);
Installs the saga middleware and initializes it to immediately begin running the provided sagas.
Params
...sagas
Provider[] Sagas you want to begin running immediately.
Returns Provider[]
boostrap(App, [
provideStore(reducer),
installSagaMiddleware(authEffect, signoutEffect)
]);
Filters a stream of SagaIteration
s to only include iterations with an action of the provided type.
Params
actionType
string Action type to filter for
Returns (iteration: SagaIteration) => boolean
return saga$ => saga$
.filter(whenAction('AUTH'))
Function you can pass in to map a saga iteration to the payload of that iteration's action
return saga$ => saga$
.map(toPayload)
.do(payload => { ... });
Applies a selector function to the state part of a saga iteration, returning a new saga iteration composed of the action and the selected piece of state
Params
selector
Observable => Observable Selector function to apply to the state
Returns Observable<SagaIteration<V>>
function selectTodos() {
return (state$: Observable<{ todos: string[] }>) => state$
.map(s => s.todos)
.distinctUntilChanged();
}
return saga$ => saga$
.let(applySelector(selectTodos))