Gathering detailed insights and metrics for @datalayer/typescript-fsa-redux-observable
Gathering detailed insights and metrics for @datalayer/typescript-fsa-redux-observable
Gathering detailed insights and metrics for @datalayer/typescript-fsa-redux-observable
Gathering detailed insights and metrics for @datalayer/typescript-fsa-redux-observable
npm install @datalayer/typescript-fsa-redux-observable
Typescript
Module System
Node Version
NPM Version
56.1
Supply Chain
95.7
Quality
77.2
Maintenance
100
Vulnerability
99.6
License
Total Downloads
19,744
Last Day
4
Last Week
26
Last Month
122
Last Year
3,971
Minified
Minified + Gzipped
Latest Version
0.18.0
Package Id
@datalayer/typescript-fsa-redux-observable@0.18.0
Unpacked Size
8.03 kB
Size
2.64 kB
File Count
5
NPM Version
6.14.5
Node Version
14.5.0
Cumulative downloads
Total Downloads
Last Day
300%
4
Compared to previous day
Last Week
18.2%
26
Compared to previous week
Last Month
103.3%
122
Compared to previous month
Last Year
-69.1%
3,971
Compared to previous year
yarn add typescript-fsa-redux-observable
Example:
1 2 3// for actions 4import actionCreatorFactory, { AnyAction, Action, Success } from 'typescript-fsa'; 5 6// for reducers 7import { reducerWithInitialState } from 'typescript-fsa-reducers'; 8import { combineReducers } from 'redux'; 9 10//for epics 11import { delay, map, tap, ignoreElements } from 'rxjs/operators'; 12import { ofAction, ofActionPayload } from 'typescript-fsa-redux-observable'; // <-- here 13import { combineEpics, Epic, createEpicMiddleware } from 'redux-observable'; 14 15//reducer 16import {createStore, applyMiddleware} from 'redux'; 17 18 19// action 20const actionCreator = actionCreatorFactory(); 21const actions = { 22 increment: actionCreator.async<undefined, undefined>('INCREMENT'), 23 decrement: actionCreator.async<undefined, undefined>('DECREMENT') 24}; 25 26// reducers & state 27 28interface State { 29 counter: number; 30} 31 32const counter = reducerWithInitialState(0) 33 .case(actions.increment.done, state => state + 1) 34 .case(actions.decrement.done, state => state - 1); 35const rootReducer = combineReducers({ 36 counter 37}); 38 39// epics 40const counterIncrementEpic: Epic<AnyAction, Action<Success<undefined, undefined>>, State> = 41 action$ => 42 action$.pipe( 43 ofActionPayload(actions.increment.started), 44 delay(300), 45 map(payload => actions.increment.done({ 46 params: payload, 47 result: undefined 48 })) 49 ); 50 51const counterDecrementEpic: Epic<AnyAction, Action<Success<undefined, undefined>>, State> = 52 action$ => 53 action$.pipe( 54 ofActionPayload(actions.decrement.started), 55 delay(300), 56 map(payload => actions.decrement.done({ 57 params: payload, 58 result: undefined 59 })) 60 ); 61 62const loggingEpic: Epic<AnyAction, AnyAction, State> = 63 action$ => 64 action$.pipe( 65 ofAction( 66 actions.decrement.started, 67 actions.increment.started, 68 ), 69 tap(action => console.log(action.type)), 70 ignoreElements() 71 ); 72 73 74const rootEpic = combineEpics( 75 counterIncrementEpic, 76 counterDecrementEpic, 77 loggingEpic, 78); 79 80const epicMiddleware = createEpicMiddleware<AnyAction, AnyAction, State>(); 81const store = createStore(rootReducer, applyMiddleware(epicMiddleware)); 82epicMiddleware.run(rootEpic); 83 84// tool 85async function sleep(time: number) { 86 return new Promise<void>(resolve => { 87 setTimeout(() => (resolve()), time) 88 }) 89} 90 91it("increment decrement test", async () => { 92 expect(store.getState()).toEqual({ counter: 0 }); 93 94 store.dispatch(actions.increment.started(undefined)); 95 expect(store.getState()).toEqual({ counter: 0 }); 96 97 await sleep(300); 98 expect(store.getState()).toEqual({ counter: 1 }); 99 100 store.dispatch(actions.decrement.started(undefined)); 101 expect(store.getState()).toEqual({ counter: 1 }); 102 103 await sleep(300); 104 expect(store.getState()).toEqual({ counter: 0 }) 105}); 106
No vulnerabilities found.
No security vulnerabilities found.