Skip to content

Instantly share code, notes, and snippets.

@jibwa
Last active December 4, 2019 23:28
Show Gist options
  • Save jibwa/2ce7d12bdc5ae9373f57ed1275ad3266 to your computer and use it in GitHub Desktop.
Save jibwa/2ce7d12bdc5ae9373f57ed1275ad3266 to your computer and use it in GitHub Desktop.
Appropriate mutation
// HELPER at top of file, or in util
const cloneSetAllSelected = (serviceHosts, selected: boolean = false) => {
return serviceHosts.map(service => ({
...service,
selected,
hosts: service.hosts.map(host => ({
..host,
selected
}))
}));
}
selectExisting(
context: StateContext<ServiceDetailDialogModel>,
{ payload: {
existingServiceHosts
} }: ServiceDetailDialogActions.SelectExisting) {
// Reset any previous state:
const { serviceHosts } = context.getState();
context.patchState({
serviceHosts: cloneSetAllSelected(serviceHosts, false)
});
}
reset(context: StateContext<ServiceDetailDialogModel>) {
const { serviceHosts } = context.getState();
context.patchState({
serviceFilter: '',
hostFilter: ''
serviceHosts: cloneSetAllSelected(serviceHosts, false)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment