Last active
December 4, 2019 23:28
-
-
Save jibwa/2ce7d12bdc5ae9373f57ed1275ad3266 to your computer and use it in GitHub Desktop.
Appropriate mutation
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
// 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