Skip to content

Instantly share code, notes, and snippets.

@trinhvanhuy
Created January 15, 2019 12:22
Show Gist options
  • Save trinhvanhuy/77fc7c7c23c4686875ef049c73ac3fb6 to your computer and use it in GitHub Desktop.
Save trinhvanhuy/77fc7c7c23c4686875ef049c73ac3fb6 to your computer and use it in GitHub Desktop.
Spinner - Global Reducer
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