Gathering detailed insights and metrics for ts-action-operators
Gathering detailed insights and metrics for ts-action-operators
Gathering detailed insights and metrics for ts-action-operators
Gathering detailed insights and metrics for ts-action-operators
npm install ts-action-operators
Typescript
Module System
Node Version
NPM Version
90.1
Supply Chain
100
Quality
76
Maintenance
100
Vulnerability
100
License
TypeScript (94.59%)
JavaScript (5.33%)
Shell (0.08%)
Total Downloads
1,281,110
Last Day
2,382
Last Week
11,226
Last Month
50,193
Last Year
476,127
MIT License
185 Stars
410 Commits
11 Forks
6 Watchers
13 Branches
3 Contributors
Updated on Dec 28, 2024
Minified
Minified + Gzipped
Latest Version
9.1.2
Package Id
ts-action-operators@9.1.2
Unpacked Size
22.57 kB
Size
5.86 kB
File Count
19
NPM Version
6.14.12
Node Version
14.16.1
Cumulative downloads
Total Downloads
Last Day
90.4%
2,382
Compared to previous day
Last Week
2.2%
11,226
Compared to previous week
Last Month
-2.1%
50,193
Compared to previous month
Last Year
33.9%
476,127
Compared to previous year
The ts-action-operators
package contains RxJS operators for action observables.
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:
1import { ofType, toPayload } from "ts-action-operators"; 2const epic = actions => actions.pipe( 3 ofType(foo), 4 toPayload(), 5 tap(payload => console.log(payload.foo)), 6 ... 7);
Using pipe
is recommended; however, if you use a version of RxJS that does not include pipe
, you can use let
instead:
1import { ofType, toPayload } from "ts-action-operators"; 2import "rxjs/add/operator/let"; 3const epic = actions => actions 4 .let(ofType(foo)) 5 .let(toPayload()) 6 .do(payload => console.log(payload.foo)) 7 ...
The 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:
1.pipe( 2 ofType(thingRequested), 3 act( 4 ({ id }) => things.get(id).pipe( 5 map(thing => thingFulfilled(thing)) 6 ), 7 (error, { id }) => thingRejected(id, error) 8 ) 9)
Which is equivalent to:
1.pipe( 2 ofType(thingRequested), 3 concatMap( 4 ({ id }) => things.get(id).pipe( 5 map(thing => thingFulfilled(thing)), 6 catchError(error => thingRejected(id, error)) 7 ) 8 ) 9)
act
can also be passed a config object that includes optional complete
, operator
and unsubscribe
properties:
1.pipe( 2 ofType(thingRequested), 3 act({ 4 ({ id }) => things.get(id).pipe( 5 map(thing => thingFulfilled(thing)) 6 ), 7 error: (error, { id }) => thingRejected(id, error), 8 unsubscribe: (_ , { id }) => thingCancelled(id), 9 operator: switchMap 10 }) 11)
The unsubscribe
callback is called if the observable returned from project
is unsubscribed before a complete
or error
notification is emitted. The complete
and unsubscribe
callbacks are passed the number of actions emitted by the observable returned from project
and the input action.
The 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:
1.pipe( 2 ofType(foo), 3 tap(action => { 4 // Here, TypeScript has narrowed the type, so the action is strongly typed 5 // and individual properties can be accessed in a type-safe manner. 6 }) 7)
If multiple action creators are specified - in an array literal - the action's type will be narrowed to a union:
1.pipe(
2 ofType([foo, bar]),
3 tap(action => {
4 // Here, the action has been narrowed to either a FOO or a BAR action.
5 // Common properties will be accessible, other will require further narrowing.
6 if (isType(action, foo)) {
7 // Here, the action has been narrowed to a FOO action.
8 } else if (isType(action, bar)) {
9 // Here, the action has been narrowed to a BAR action.
10 }
11 })
12)
The toPayload
operator takes no parameters. It can be applied to an obserable stream that emits narrowed actions that contain payloads. For example:
1.pipe(
2 ofType(foo),
3 toPayload()
4 tap(payload => {
5 // Here, TypeScript has narrowed the type, so the payload is strongly typed
6 // and individual properties can be accessed in a type-safe manner.
7 })
8)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
12 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More