-
-
Save OliverJAsh/0afad9771d032193a16f40c554ec5883 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
// Wrap the epic to: | |
// - `takeUntil` the counter is removed | |
// - pass the local state into the counter epic | |
const wrappedCounterEpic = ( | |
counterId: string | |
): Epic<Action, Action, State> => (action$, state$) => { | |
const counterRemovedAction$ = action$.filter( | |
checkIsCounterRemovedAction | |
); | |
const counterStateAction$ = counterEpic( | |
action$, | |
// Note: this should be converted to a `StateObservable` | |
// type but we've skipped this to keep the example simple. | |
getCounterState(counterId)(state$.value), | |
{} | |
); | |
const counterRemoved$ = counterRemovedAction$.filter( | |
counterRemovedAction => | |
counterRemovedAction.id === counterId | |
); | |
return counterStateAction$.takeUntil(counterRemoved$); | |
}; | |
// When an "added" action is received, start a new instance of | |
// the list item epic. | |
const rootEpic: Epic<Action, Action, State> = ( | |
action$, | |
state$ | |
) => { | |
const counterAddedAction$ = action$.filter( | |
checkIsCounterAddedAction | |
); | |
const counterStateAction$ = counterAddedAction$.mergeMap( | |
counterAddedAction => | |
wrappedCounterEpic(counterAddedAction.id)( | |
action$, | |
state$, | |
{} | |
) | |
); | |
return counterStateAction$; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment