Last active
June 29, 2020 22:56
-
-
Save trumbitta/1d1e962aa72bc785c2cbaee21cc19879 to your computer and use it in GitHub Desktop.
Custom operator for using portions of state$ in redux-observable epics
This file contains hidden or 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
function withLatestFromSelector<A, R, S, I>( | |
state$: StateObservable<A>, | |
selector: OutputSelector<A, R, S>, | |
): OperatorFunction<I, Array<I | R>> { | |
return (input$) => | |
input$.pipe( | |
withLatestFrom(state$), | |
map(([input, state]) => [input, selector(state)]), | |
); | |
} | |
export const myEpic: Epic = (action$: ActionsObservable<Action>, state$: StateObservable<AppState>) => | |
action$.pipe( | |
ofType(myActions.fooAction.type), | |
withLatestFromSelector(state$, mySelector), | |
tap(([action, fromSelector]) => console.log(action, fromSelector)), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment