This file contains hidden or 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 uuid from 'uuid'; | |
export default (state = {}, action) => { | |
const { type, payload } = action; | |
const matches = /(.*)_(REQUEST|FAILURE)/.exec(type); | |
// not a *_REQUEST / *_FAILURE actions, so we ignore them | |
if (!matches) return state; | |
const [, requestName, requestState] = matches; | |
return { | |
…state, | |
// Store errorMessage |
This file contains hidden or 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
export default (state = {}, action) => { | |
const { type } = action; | |
const matches = /(.*)_(REQUEST|SUCCESS|FAILURE)/.exec(type); | |
// not a *_REQUEST / *_SUCCESS / *_FAILURE actions, so we ignore them | |
if (!matches) return state; | |
const [, requestName, requestState] = matches; | |
return { | |
…state, | |
// Store whether a request is happening at the moment or not | |
// e.g. will be true when receiving FETCH_TODOS_REQUEST |
This file contains hidden or 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
export const FETCH_TODOS_REQUEST = 'FETCH_TODOS_REQUEST'; | |
export const FETCH_TODOS_SUCCESS = 'FETCH_TODOS_SUCCESS'; | |
export const FETCH_TODOS_FAILURE = 'FETCH_TODOS_FAILURE'; |
This file contains hidden or 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
// todo/actions.js | |
export const getEvents = (dispatch) => () => { | |
dispatch({ type: 'GET_EVENTS_REQUEST' }); | |
return fetch('/api/v1/events') | |
.then((todos) => dispatch({ type: 'GET_EVENTS_SUCCESS', payload: todos }) | |
.catch((error) => dispatch({ type: 'GET_EVENTS_FAILURE', payload: error, error: true }); | |
}; |
This file contains hidden or 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
// events/reducer.js | |
const initialState = { todos: [] }; | |
export const eventsReducer = (state = initialState, action) => { | |
switch(action.type) { | |
case 'GET_EVENTS_REQUEST': | |
return { ...state, isFetching: true }; | |
case 'GET_EVENTS_SUCCESS': | |
return { ...state, isFetching: false, todos: action.payload }; | |
case 'GET_EVENTS_FAILURE': | |
return { ...state, isFetching: false, errorMessage: action.payload.message }; |
This file contains hidden or 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 } from 'redux'; | |
// local import | |
import reducers from '../reducers'; | |
const store = | |
reducers && | |
createStore(reducers); | |
export default store; |
This file contains hidden or 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
const INITIAL_STATE = { | |
orderList: {}, | |
isRetrievingOrder: false, | |
errorRetrievingOrder: false, | |
errorRetrievingOrderMessage: null, | |
isSavingOrder: false, | |
errorSavingOrder: false, | |
errorSavingOrderMessage: null, | |
isCancellingOrder: false, | |
errorCancellingOrder: false, |
This file contains hidden or 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
const rootReducer = (state, action) => { | |
// when a logout action is dispatched it will reset redux state | |
if (action.type === 'USER_LOGGED_OUT') { | |
const { users, comment } = state; | |
state = { users, comment }; | |
} | |
if (action.type === 'USER_LOGGED_IN') { |
This file contains hidden or 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 { combineReducers } from 'redux'; | |
import AppReducer from './AppReducer'; | |
import UsersReducer from './UsersReducer'; | |
import OrderReducer from './OrderReducer'; | |
import NotificationReducer from './NotificationReducer'; | |
import CommentReducer from './CommentReducer'; | |
const appReducer = combineReducers({ | |
/* your app’s top-level reducers */ |
This file contains hidden or 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
const rootReducer = (state, action) => { | |
if (action.type === USER_LOGGED_OUT) { | |
// for all keys defined in your persistConfig(s) | |
storage.removeItem('persist:root') | |
// storage.removeItem('persist:otherKey') | |
state = undefined; | |
} | |
return appReducer(state, action); | |
}; |