Last active
May 7, 2021 10:14
-
-
Save oliverlin/b4312a84545a2f11ec59693fa406e318 to your computer and use it in GitHub Desktop.
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
// 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