Created
March 19, 2018 14:43
-
-
Save navarroaxel/e79582a048c3643fec8a2feee4866361 to your computer and use it in GitHub Desktop.
redux-saga - takeLast
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 default function* root() { | |
yield [ | |
fork(fetchByParams) | |
] |
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 function* handleSearch(param) { | |
yield call(delay, 500); | |
const companiesData = yield call(CompanyService.fetchByParams, param); | |
yield put(receiveCompaniesData(companiesData.companies)); | |
} | |
export function* fetchByParams() { | |
let task; | |
while (true) { | |
const {param} = yield take(FETCH_COMPANIES_BY_PARAMS); | |
if (task) { | |
yield cancel(task); | |
} | |
task = yield fork(handleSearch, param); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment