Created
April 28, 2018 20:48
-
-
Save timdeschryver/6e1bc20fbf8d09e6849360d983ab939d 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
// State | |
export interface State { | |
customers: Customer[]; | |
selectedCustomer: Customer; | |
} | |
// Reducer | |
export function reducer(state, action) { | |
switch (action.type) { | |
... | |
case EDIT_CUSTOMER: | |
return { | |
customers: state.customers.map(c => (c.id === action.payload.id ? action.payload : c)), | |
selectedCustomer: | |
state.selectedCustomer && state.selectedCustomer.id === action.payload.id | |
? action.payload | |
: state.selectedCustomer, | |
}; | |
... | |
} | |
} | |
// Selectors | |
export const selectCustomers = createSelector(selectCustomersState, state => state.customers); | |
export const selectSelectedCustomer = createSelector(selectCustomersState, state => state.selectedCustomer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment