Last active
March 24, 2020 08:22
-
-
Save LironHazan/10ba83735865885678bcbfef55b81586 to your computer and use it in GitHub Desktop.
Get new ref of your entity to achieve immutability (reduces bugs) and pass entity by ref when using onPush when working in Angular e.g.
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
class updateEditorExample { | |
private queryEditorState: Readonly<QueryEditorState>; | |
static updateEditorState (editorState: Readonly<QueryEditorState>, sliceToUpdate: Partial<Readonly<QueryEditorState>>) { | |
return { ...editorState, ...sliceToUpdate }; | |
} | |
// Get new state: | |
doSomthingGood(newText: string) { | |
this.queryEditorState = updateEditorExample.updateEditorState(this.queryEditorState, { text: newText }); | |
} | |
// Will throw compilation err: | |
doSomthingBad(newText: string) { | |
this.queryEditorState.text = newText; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment