What is it?
ts-action-operators package contains RxJS operators for action observables.
Why might you need it?
I created the
ts-action package because I wanted a mechanism for declaring and consuming actions that involved writing as little boilerplate as possible. And I created this package so that I could apply the TypeScript narrowing mechanisms in
ts-action to the composition of NgRx effects and redux-observable epics.
If you, too, want less cruft in your effects or epics, you might find this package useful.
For an in-depth look at TypeScript, Redux and
ts-action, have a look at: How to Reduce Action Boilerplate.
Install the package using npm:
npm install ts-action-operators --save
The package includes operators for filtering and narrowing actions and for selecting strongly typed payloads. The operators can be used in NgRx effects or redux-observable epics, like this:
pipe is recommended; however, if you use a version of RxJS that does not include
pipe, you can use
act operator is a convenience operator that facilitates the mapping of an input action to an output action with as little boilerplate as possible and with some sensible defaults. It also ensures that errors are handled and that
catchError is called in the correct location.
act can be passed a
project function and
error selector, like this:
Which is equivalent to:
act can also be passed a config object that includes optional
unsubscribe callback is called if the observable returned from
project is unsubscribed before a
error notification is emitted. The
unsubscribe callbacks are passed the number of actions emitted by the observable returned from
project and the input action.
ofType operator can be passed
ts-action-declared action creators. The operator will remove unwanted actions from the observable stream.
If only a single action creator is specified, the action's type will be narrowed. For example:
If multiple action creators are specified - in an array literal - the action's type will be narrowed to a union:
toPayload operator takes no parameters. It can be applied to an obserable stream that emits narrowed actions that contain payloads. For example: