Created
January 15, 2019 12:22
-
-
Save trinhvanhuy/77fc7c7c23c4686875ef049c73ac3fb6 to your computer and use it in GitHub Desktop.
Spinner - Global Reducer
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 { assign } from '@utils/reducer'; | |
import { | |
GlobalActionTypes, | |
GlobalActionsUnion | |
} from '@app/core/actions/global.action'; | |
export interface State { | |
spinnerCounter: number; | |
} | |
const initialState: State = { | |
spinnerCounter: 0 | |
}; | |
export function reducer( | |
state: State = initialState, | |
action: GlobalActionsUnion | |
): State { | |
switch (action.type) { | |
case GlobalActionTypes.ShowSpinner: { | |
return { | |
spinnerCounter: state.spinnerCounter + 1 | |
}; | |
} | |
case GlobalActionTypes.HideSpinner: { | |
return { | |
spinnerCounter: state.spinnerCounter > 0 ? state.spinnerCounter - 1 : 0 | |
}; | |
} | |
default: | |
return state; | |
} | |
} | |
export const getSpinnerCounter = (state: State) => state.spinnerCounter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment