Created
February 16, 2017 09:50
-
-
Save mitu217/82f4a083743a0fbeb6fbf5b54f6bad98 to your computer and use it in GitHub Desktop.
React + Redux + Redux-saga
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 { takeEvery, delay } from 'redux-saga'; | |
import { put, call } from 'redux-saga/effects'; | |
import { increment } from './actions'; | |
export function* incrementAsync() { | |
yield call(delay, 1000); | |
yield put(increment()); | |
} | |
export default function* rootSaga() { | |
yield* takeEvery('increment', incrementAsync); | |
} |
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 createSagaMiddleware from 'redux-saga'; | |
import rootReducer from './reducers'; | |
import saga from './sagas'; | |
export default function configureStore(initialState) { | |
const sagaMiddleware = createSagaMiddleware(); | |
const store = createStore( | |
rootReducer, | |
initialState, | |
applyMiddleware( | |
sagaMiddleware, | |
) | |
); | |
sagaMiddleware.run(saga); | |
return store; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment