Last active
April 30, 2018 04:26
-
-
Save Calvin-Huang/698cbb954d714a41c1726d0cee1be629 to your computer and use it in GitHub Desktop.
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
// Debouncing | |
function* handleInput(input) { | |
// debounce by 500ms | |
yield call(delay, 500) | |
... | |
} | |
function* watchInput() { | |
let task | |
while (true) { | |
const { input } = yield take('INPUT_CHANGED') | |
if (task) { | |
yield cancel(task) | |
} | |
task = yield fork(handleInput, input) | |
} | |
} | |
// Debouncing written by takeLatest | |
function* handleInput({ input }) { | |
// debounce by 500ms | |
yield call(delay, 500) | |
... | |
} | |
function* watchInput() { | |
// will cancel current running handleInput task | |
yield takeLatest('INPUT_CHANGED', handleInput); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment