Last active
November 11, 2019 17:05
-
-
Save evgenyfedorenko/8372fb40ae2dfe29b0949eb099e0208e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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