Created
November 28, 2017 13:40
-
-
Save dmtrmrtnv/7bdfaa5bf34f086653c1df02b75fc9e1 to your computer and use it in GitHub Desktop.
Redux-observable epic with polling.
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
const loadGames = (action$, store, scheduler, timeout = 1000 * 30, debounce = 350) => | |
action$ | |
.ofType('LOAD_GAMES') | |
.debounceTime(debounce, scheduler) | |
.switchMap(({ payload: { date } }) => | |
of({ | |
type: 'SET_GAMES_LOADING', payload: { date }, | |
}) | |
.merge(ajax({ | |
url: `${url}date/${date}`, | |
responseType: 'json', | |
}) | |
.map(({ response }) => ({ | |
type: 'RECEIVE_GAMES', payload: { date, items: response }, | |
})) | |
.repeatWhen(o => o.concatMap(() => timer(timeout, timeout, scheduler))) | |
.retryWhen(e => e.delay(timeout, scheduler)) | |
.takeUntil(action$.ofType('LOAD_GAMES_CANCEL')))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment