Skip to content

Instantly share code, notes, and snippets.

@LironHazan
Last active March 26, 2020 08:25
Show Gist options
  • Save LironHazan/29881db19edfa10777bce94f62bbf534 to your computer and use it in GitHub Desktop.
Save LironHazan/29881db19edfa10777bce94f62bbf534 to your computer and use it in GitHub Desktop.
class FunWithFunctionalTS {
queryEditorState: Readonly<QueryEditorState>;
static updateEditorState(
editorState: Readonly<QueryEditorState>,
sliceToUpdate: Partial<Readonly<QueryEditorState>>
): Readonly<QueryEditorState> {
return { ...editorState, ...sliceToUpdate };
}
updateEditorOnParseResult(result: Partial<ParseTextResult>): Partial<ParseTextResult> {
this.queryEditorState = FunWithFunctionalTS.updateEditorState(this.queryEditorState, {
valid: result.isValid,
textTokens: result.tokenList
});
return result;
}
doSomething() {
// g after f LOL
const result = this.updateEditorOnParseResult(this.parseEditorText(this.queryEditorState.text));
console.log(result);
}
}
@LironHazan
Copy link
Author

Actually it will be better if the updateEditorOnParseResult will be void - in this example I just wanted a one line composition in practice I'll split it..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment