UNPKG

utilitaire

Version:

Common utils for JavaScript and Typescript development

20 lines (14 loc) 576 B
import deepAssign from "./DeepAssign"; import {JsObject} from "./DeepAssign"; export class HasDescriptor<Desc extends JsObject , UDesc extends JsObject>{ constructor(protected desc : Desc){} updateInPlace(updateDescriptor : UDesc) : this { this.desc = Object.assign(this.desc, updateDescriptor) as Desc; return this; } copy(updateDescriptor : UDesc) : this { const newDescriptor = deepAssign(this.desc, updateDescriptor); const constructWith = this.constructor; return constructWith(newDescriptor) as this; } }