Skip to content

Instantly share code, notes, and snippets.

@evgenyfedorenko
Last active November 11, 2019 17:05
Show Gist options
  • Save evgenyfedorenko/8372fb40ae2dfe29b0949eb099e0208e to your computer and use it in GitHub Desktop.
Save evgenyfedorenko/8372fb40ae2dfe29b0949eb099e0208e to your computer and use it in GitHub Desktop.
...
actions$: BehaviorSubject<Action>;
state$: BehaviorSubject<any>;
constructor() {
this.actions$ = new BehaviorSubject({ type: 'INIT' });
const actionsOnQueue$: Observable<Action> = this.actions$.pipe(observeOn(queueScheduler));
const reducer$: Observable<
ActionReducer<any, any>
> = new BehaviorSubject(reducerFactory(reducers));
const withLatestReducer$: Observable<
[Action, ActionReducer<any, Action>]
> = actionsOnQueue$.pipe(withLatestFrom(reducer$));
this.state$ = new BehaviorSubject({});
const stateAndAction$: Observable<
{ state: any; action?: Action; }
> = withLatestReducer$.pipe(
scan(reduceState, { state: {} }
)
);
stateAndAction$.subscribe(({ state }) => {
this.state$.next(state);
});
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment