Created
July 6, 2017 16:13
-
-
Save guimello/2120ff301a367491ecf9fb0304b80bde to your computer and use it in GitHub Desktop.
Throttle with batch execution of actions - Redux Saga
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
import { buffers, delay } from 'redux-saga' | |
import { actionChannel, call, fork, take, flush } from 'redux-saga/effects' | |
import { flatten } from "ramda"; | |
yield fork(function* () { | |
const leChannel = yield actionChannel("LOL", buffers.expanding(20)); | |
while (true) { | |
const currentAction = yield take(leChannel); | |
yield call(delay, 1000); | |
const actions = yield flush(leChannel); | |
yield fork(function* (actions) { | |
console.log("le actions", actions); | |
}, flatten([currentAction, actions])) | |
} | |
}); | |
// and then play around | |
(() => { | |
let a = 0; | |
const interval = setInterval(() => { | |
store.dispatch({type: "LOL", payload: a++}) | |
if (a === 40) clearInterval(interval); | |
}, 400); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment