Created
December 4, 2019 23:23
-
-
Save jibwa/d366c63a5d52ec001e3b77a3090b2938 to your computer and use it in GitHub Desktop.
updateItem example no mutation
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
selectService( | |
context: StateContext<ServiceDetailDialogModel>, | |
{ payload: { | |
serviceName, | |
doSelect | |
} }: ServiceDetailDialogActions.SelectService) { | |
const { serviceHosts } = context.getState(); | |
// get the index | |
const serviceIndex: number = serviceHosts.findIndex(service_ => service_.serviceName === serviceName); | |
if (serviceIndex < 0) { | |
//throw error or something? | |
} | |
// clone and update | |
const service = { | |
...serviceHosts[serviceIndex], | |
selected: doSelect, | |
hosts: hosts.map(host => ({ | |
...host, | |
selected: doSelect | |
})) | |
}; | |
ctx.setState( | |
patch({ | |
serviceHosts: updateItem(serviceIndex, service) | |
}) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment