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