Created
April 20, 2017 21:50
-
-
Save dminuoso/605bc2a2970b850a2e727f38333f5075 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
export const searchWatchStart = (searchConstants, selectSearch, apiFn, handleError) => { | |
const searchCreators = createRequestCreators(searchConstants.FETCH_STATUS); | |
const loadResults = fetchEntity.bind(null, searchCreators, apiFn, { handleError }); | |
const selectMask = makeSelectMask(selectSearch); | |
return function* () { // eslint-disable-line func-names | |
let lastTask; | |
for (;;) { | |
const { wait } = yield take(searchConstants.START_SEARCH); | |
if (lastTask) { | |
yield cancel(lastTask); | |
} | |
const searchMask = yield select(selectMask); | |
lastTask = yield fork(function* () { // eslint-disable-line func-names | |
if (wait) { | |
yield call(delay, wait); | |
} | |
yield call(loadResults, searchMask); | |
}); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment