Skip to content

Instantly share code, notes, and snippets.

@yelouafi
Created January 28, 2016 13:09
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 yelouafi/baf20b6e7e2685d6f08d to your computer and use it in GitHub Desktop.
Save yelouafi/baf20b6e7e2685d6f08d to your computer and use it in GitHub Desktop.
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