Skip to content

Instantly share code, notes, and snippets.

@oliverlin
Last active May 7, 2021 10:14
Show Gist options
  • Save oliverlin/b4312a84545a2f11ec59693fa406e318 to your computer and use it in GitHub Desktop.
Save oliverlin/b4312a84545a2f11ec59693fa406e318 to your computer and use it in GitHub Desktop.
// createStore.js
const reducer = combine(reducerRegistry.getReducers())
const store = createStore(reducer)
reducerRegistry.setChangeListener(reducers => {
store.replaceReducer(combine(reducers))
})
// data/jobs.js
export default function reducer(state = initialState, action = {}) {
switch (action.type) {
case HYDRATE:
return action.state.jobs || state
case ADD_JOB:
return [...state, { ...action.payload, id: jobId += 1 }]
case REMOVE_JOB:
return state.filter(job => job.id !== action.payload)
default:
return state
}
}
reducerRegistry.register('jobs', reducer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment