Skip to content

Instantly share code, notes, and snippets.

@erezrokah
Last active June 5, 2017 12:14
Show Gist options
  • Save erezrokah/be9763c0a2c6af030d86f6926eaeef36 to your computer and use it in GitHub Desktop.
Save erezrokah/be9763c0a2c6af030d86f6926eaeef36 to your computer and use it in GitHub Desktop.
//@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