Skip to content

Instantly share code, notes, and snippets.

@kiok46
Created June 10, 2018 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiok46/d01f0931fe38662826e2594d5b6fb9a1 to your computer and use it in GitHub Desktop.
Save kiok46/d01f0931fe38662826e2594d5b6fb9a1 to your computer and use it in GitHub Desktop.
Redux, Reactotron, Actions, Reducers and Sagas (2)
import { put, take, fork } from 'redux-saga/effects';
import { TEXT_CHANGED, TEXT_CHANGED_SUCCESS } from '../types';
// ****************
// WORKERS
// ****************
function* workerTextChanged(action) {
console.log(action);
// {type: "text_changed", payload: "-_-"}
try {
yield put({ type: TEXT_CHANGED_SUCCESS, text: action.payload });
} catch (e) {
console.log('Error', e);
}
}
// ****************
// WATCHERS
// ****************
export function* watcherTextChanged() {
while (true) {
const action = yield take(TEXT_CHANGED);
yield fork(workerTextChanged, action);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment