Created
January 28, 2016 13:09
-
-
Save yelouafi/baf20b6e7e2685d6f08d to your computer and use it in GitHub Desktop.
This file contains 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
import { createStore, applyMiddleware } from 'redux' | |
import sagaMiddleware, { runSaga, storeIO, take, put } from 'redux-saga' | |
/////////////////////////////////////////////////////////////////// | |
// | |
// Sagas | |
// | |
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)) | |
function* midSaga1() { | |
const action = yield take('RUNSAGA_ACTION') | |
console.log('mid-1 take', action) | |
yield delay(0) | |
yield put({type: 'MIDDLEWARE_SAGA'}) | |
} | |
function* midSaga2() { | |
let action = yield take('RUNSAGA_ACTION') | |
console.log('mid-2 take', action) | |
action = yield take('MIDDLEWARE_SAGA') | |
console.log('mid-2 take', action) | |
} | |
function reducer(state=[], action) { | |
return [...state, action] | |
} | |
const store = applyMiddleware(sagaMiddleware(midSaga1, midSaga2))(createStore)(reducer) | |
runSaga(function*() { | |
yield put({type: 'RUNSAGA_ACTION'}) | |
const action = yield take('MIDDLEWARE_SAGA') | |
console.log('runSaga take', action) | |
}(), storeIO(store)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment