Created
February 18, 2022 22:44
-
-
Save hmetgundogdu/c770f0dc58578ffbcedfe9655278ddd3 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
| export const INITIAL_STATE = { | |
| init: false, | |
| network: false, | |
| errors: [] as Error[], | |
| }; | |
| export type AppState = typeof INITIAL_STATE; | |
| interface INIT_STATE_TYPE { type: 'INIT_STATE' }; | |
| interface NETWORK_DOWN { type: 'NETWORK_DOWN' }; | |
| interface NETWORK_UP { type: 'NETWORK_UP' }; | |
| interface PUT_ERROR { type: 'PUT_ERROR', payload: Error }; | |
| type Action = INIT_STATE_TYPE | NETWORK_DOWN | NETWORK_UP | PUT_ERROR; | |
| export function reducer(state: AppState, action: Action) { | |
| switch (action.type) { | |
| case 'INIT_STATE': | |
| return { | |
| ...state, | |
| init: true, | |
| }; | |
| case 'NETWORK_DOWN': | |
| return { | |
| ...state, | |
| network: false, | |
| }; | |
| case 'NETWORK_UP': | |
| return { | |
| ...state, | |
| network: true, | |
| }; | |
| case 'PUT_ERROR': | |
| return { | |
| ...state, | |
| errors: [...state.errors, action.payload], | |
| }; | |
| default: | |
| return state; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment