3.1.3 • Published 5 years ago

@reactive-redux/async-store v3.1.3

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

npm version

Reactive state container

Install

npm i @reactive-redux/async-store

Example

import { of, Subject, interval } from 'rxjs';
import { map, take } from 'rxjs/operators';
import {
  Action,
  AsyncStore,
  AsyncType,
  select
} from '@reactive-redux/async-store';

//Counter example
interface State {
  count: number;
}

class Increment extends Action {
  constructor(public payload: number) {
    super();
  }
}

class Decrement extends Action {
  constructor(public payload: number) {
    super();
  }
}

type ActionsUnion = Increment | Decrement;

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

const initialState = {
  count: 0
};

const initialState$ = of(initialState);
const actions$ = actionQ.asObservable();

const actionMap$ = of({
  [Increment.name]: (state: State, action: Increment) => ({
    ...state,
    count: state.count + action.payload
  }),
  [Decrement.name]: (state: State, action: Decrement) => ({
    ...state,
    count: state.count - action.payload
  })
});

const store = new AsyncStore<State, ActionsUnion>({
  initialState$,
  actions$,
  actionMap$
});

store.state$.pipe(select(state => state.count)).subscribe(console.log);

const add100 = new Increment(100);

const add100times5 = interval(200).pipe(
  map(() => add100),
  take(5)
);

actionQ.next(add100times5);

Changelog

Want to help?

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.6

5 years ago

1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago