Utilisation de React pour le client
This commit is contained in:
5
client/src/store/reducers/issues.js
Normal file
5
client/src/store/reducers/issues.js
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
export function issuesReducer(state = {}, action) {
|
||||
|
||||
return state;
|
||||
}
|
6
client/src/store/reducers/root.js
Normal file
6
client/src/store/reducers/root.js
Normal file
@ -0,0 +1,6 @@
|
||||
import { combineReducers } from 'redux';
|
||||
import { issuesReducer } from './issues';
|
||||
|
||||
export const rootReducer = combineReducers({
|
||||
issues: issuesReducer,
|
||||
});
|
4
client/src/store/sagas/failure.js
Normal file
4
client/src/store/sagas/failure.js
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
export function* handleFailedActionSaga(action) {
|
||||
console.error(action.error);
|
||||
}
|
14
client/src/store/sagas/root.js
Normal file
14
client/src/store/sagas/root.js
Normal file
@ -0,0 +1,14 @@
|
||||
import { all, takeEvery } from 'redux-saga/effects';
|
||||
import { handleFailedActionSaga } from './failure';
|
||||
|
||||
export function* rootSaga() {
|
||||
yield all([
|
||||
takeEvery(patternFromRegExp(/^.*_FAILURE/), handleFailedActionSaga),
|
||||
]);
|
||||
}
|
||||
|
||||
export function patternFromRegExp(re) {
|
||||
return (action) => {
|
||||
return re.test(action.type);
|
||||
};
|
||||
}
|
28
client/src/store/store.js
Normal file
28
client/src/store/store.js
Normal file
@ -0,0 +1,28 @@
|
||||
import { createStore, applyMiddleware } from 'redux'
|
||||
import createSagaMiddleware from 'redux-saga'
|
||||
import { rootReducer } from './reducers/root'
|
||||
import { rootSaga } from './sagas/root'
|
||||
|
||||
let reduxMiddlewares = [];
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
const createLogger = require('redux-logger').createLogger;
|
||||
const loggerMiddleware = createLogger({
|
||||
collapsed: true,
|
||||
diff: true
|
||||
});
|
||||
reduxMiddlewares.push(loggerMiddleware);
|
||||
}
|
||||
|
||||
// create the saga middleware
|
||||
const sagaMiddleware = createSagaMiddleware()
|
||||
reduxMiddlewares.push(sagaMiddleware);
|
||||
|
||||
// mount it on the Store
|
||||
export const store = createStore(
|
||||
rootReducer,
|
||||
applyMiddleware(...reduxMiddlewares)
|
||||
)
|
||||
|
||||
// then run the saga
|
||||
sagaMiddleware.run(rootSaga);
|
Reference in New Issue
Block a user