Last active
August 3, 2020 06:08
-
-
Save jakejrichards/778c17e657358035e929d89618614f8b 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
import produce from 'immer'; | |
import { ApplicationState, ApplicationAction } from './types'; | |
export const initialState: ApplicationState = { | |
loading: { | |
users: false, | |
}, | |
users: [], | |
} | |
const reducer = (state = initialState, action: ApplicationAction) => { | |
switch (action.type) { | |
case "loadUsersRequest": | |
return produce(state, draft => { | |
draft.loading.users = true; | |
}); | |
case "loadUsersSuccess": | |
return produce(state, draft => { | |
draft.loading.users = false; | |
draft.users = action.users; | |
}); | |
case "loadUsersError": | |
return produce(state, draft => { | |
draft.loading.users = false; | |
}); | |
} | |
} | |
export default reducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment