Skip to content

Instantly share code, notes, and snippets.

@shapkarin
Last active June 21, 2019 21:21
Show Gist options
  • Save shapkarin/bc473e4d3f944a57ecb9b1ab2e3dc719 to your computer and use it in GitHub Desktop.
Save shapkarin/bc473e4d3f944a57ecb9b1ab2e3dc719 to your computer and use it in GitHub Desktop.
redux-saga fetch worker example
import { fork, debounce } from 'redux-saga/effects';
import fetch from './fetch';
import { fetchSomeInfo } from './someApi';
import {
loadSomeInfoStart,
loadSomeInfoSuccess,
loadSomeInfoError
} from './actions';
function* autocompleteExample (action){
yield fork(fetch, {
action,
method: fetchSomeInfo,
start: loadSomeInfoStart,
success: loadSomeInfoSuccess,
error: loadSomeInfoError
});
}
function* mySaga () {
yield debounce(300, 'INPUT_CHANGED', autocompleteExample);
}
/*
not it's npm package
https://www.npmjs.com/package/saga-fetch
https://github.com/shapkarin/saga-fetch
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment