Skip to content

Instantly share code, notes, and snippets.

@brakmic
Created April 11, 2017 09:07
Show Gist options
  • Save brakmic/6b8b8544197ee3ccf0a6eeb3e60f53f6 to your computer and use it in GitHub Desktop.
Save brakmic/6b8b8544197ee3ccf0a6eeb3e60f53f6 to your computer and use it in GitHub Desktop.
reducer for handling customer actions
import { ICustomerState, initialCustomerState } from '../states/sub-states';
import { CustomerAction, CustomerActionTypes } from '../actions';
export function customerReducer(
state: ICustomerState = initialCustomerState,
action: CustomerAction
): ICustomerState {
switch (action.type) {
case CustomerActionTypes.INITIALIZED:
return (<any>Object).assign({}, state, {
customer: action.payload
});
case CustomerActionTypes.SAVED:
return (<any>Object).assign({}, state, {
customer: action.payload
});
case CustomerActionTypes.DELETED:
return (<any>Object).assign({}, state, {
customer: undefined
});
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment