@reactive-redux/store
TypeScript icon, indicating that this package has built-in type declarations

6.3.12 • Public • Published

npm version

Reactive state container

Install

npm i rxjs ts-action reselect @reactive-redux/store

Example

import { of, Subject, interval } from 'rxjs';
import { map, take } from 'rxjs/operators';
import {
  createStore
} from '@reactive-redux/store';
import { action, on, payload, reducer } from "ts-action";

const actionQ = new Subject<AsyncType<ActionsUnion>>();

const increment = action("Increment", payload<{ value: number }>());
const decrement = action("Decrement", payload<{ value: number }>());

interface State {
  value: number;
  }

const initialState: State = {
  value: 0;
};

const initialState$ = of(initialState);
const actionStream$ = actionQ.asObservable();
const reducer$ = of(reducer(
  initialState,
  on(increment, (state, { payload }) => ({ value: state.value + payload.value })),
  on(decrement, (state, { payload }) => ({ value: state.value - payload.value }))
));

const { state$ } = createStore<State, ActionsUnion>({
  actionStream$,
  reducer$,
  initialState$
});

state$.subscribe(console.log);
 
const add1 = increment({ value: 1 });
 
const add1times = n => interval(200).pipe(
  map(() => add1),
  take(n)
);
 
//dispaching an observable action
actionQ.next(add1times(10));

Changelog

Want to help?

Package Sidebar

Install

npm i @reactive-redux/store

Weekly Downloads

81

Version

6.3.12

License

MIT

Unpacked Size

26 kB

Total Files

12

Last publish

Collaborators

  • zdravko.tatarski