Last active
June 5, 2017 12:14
-
-
Save erezrokah/be9763c0a2c6af030d86f6926eaeef36 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
//@flow | |
import createReducer from '../createReducer' | |
export const metaTypes = { | |
messages: 'messages', | |
userContacts: 'userContacts', | |
} | |
function getInitialState() { | |
let initialState = { } | |
Object.keys(metaTypes).forEach((metaType) => { | |
initialState[metaType] = { inProgress: false, items: { } } | |
}) | |
return initialState | |
} | |
const initialState = getInitialState() | |
//createReducer taken from here http://redux.js.org/docs/recipes/ReducingBoilerplate.html | |
export const reducer = createReducer(initialState, { | |
['FIREBASE_LISTEN_REQUESTED'](state, action) { | |
const newState = { | |
...state, | |
[action.metaType]: { ...state[action.metaType], inProgress: true } | |
} | |
return newState | |
}, | |
['FIREBASE_LISTEN_FULFILLED'](state, action) { | |
const newState = { | |
...state, | |
[action.metaType]: { ...state[action.metaType], inProgress: false, items: action.items } | |
} | |
return newState | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment