Created
January 18, 2019 15:01
-
-
Save pyldin601/5d270a8a2763e050ae7c6613ca7035b2 to your computer and use it in GitHub Desktop.
Why redux-observable is better than promises, sagas and thunks
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
export type IHideToastOnTimeoutEpic = IEpic< | |
IToastShowAction | IToastDismissAction, | |
IToastDismissAction | |
>; | |
const hideToastOnTimeoutEpic: IHideToastOnTimeoutEpic = (action$, state$) => { | |
const showAction$ = action$.ofType<IToastShowAction>(TOAST_SHOW); | |
const dismissAction$ = action$.ofType<IToastDismissAction>(TOAST_DISMISS); | |
return showAction$.pipe( | |
filter(showAction => 'timeout' in showAction.payload), | |
mergeMap(showAction => | |
timer(showAction.payload.timeout).pipe( | |
takeUntil( | |
dismissAction$.pipe( | |
filter(dismissAction => dismissAction.payload.uuid === showAction.payload.uuid), | |
), | |
), | |
map(() => createToastDismissAction(showAction.payload.uuid)), | |
), | |
), | |
); | |
}; | |
export default hideToastOnTimeoutEpic; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment