@redux-tools/stream-creators v0.9.1
@redux-tools/stream-creators
The @redux-tools/epics enhancer accepts a streamCreator
option, allowing you to add an additional argument to ALL epics. This package is a collection of various useful stream creators.
Usage
import { namespacedState$ } from '@redux-tools/stream-creators';
import { makeEnhancer as makeEpicsEnhancer } from '@redux-tools/epics';
import { identity, compose } from 'ramda';
import { createStore, applyMiddleware } from 'redux';
import { createEpicMiddleware } from 'redux-observable';
const epicMiddleware = createEpicMiddleware();
const store = createStore(
identity,
compose(
makeEpicsEnhancer({ epicMiddleware, streamCreator: namespacedState$ }),
applyMiddleware(epicMiddleware)
)
);
If you want to pass multiple stream creators, you can use the applySpec
function from Ramda (or any other equivalent).
const store = createStore(
identity,
compose(
makeEpicsEnhancer({
epicMiddleware,
streamCreator: applySpec({ namespacedState$, globalAction$ }),
}),
applyMiddleware(epicMiddleware)
)
);
const epic = (action$, state$, { namespacedState$, globalAction$ }) =>
action$.pipe(ignoreElements());
API Reference
namespacedState$
A stream creator for namespaced state. Similar to state$
, except it will always be the state associated with the epic. Therefore, if you have an epic injected under the foo
namespace, namespacedState$
will use state.namespaces.foo
.
Arguments
bag
(Object): Provided by the enhancer.
Returns
(Observable): An observable similar to state$
in redux-observable, except using the namespaced state.
globalAction$
A stream creator for global actions. By default, every injected epic only accepts actions matching its namespace (see @redux-tools/namespaces for more info). This stream creator allows you to react to actions from other namespaces if you need to.
Arguments
bag
(Object): Provided by the enhancer.
Returns
(Observable): The original unfiltered action$
passed to the epic.