From 9bc3c2ad12b7f5926d2b6180163b9b95e3ef01f5 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 21 Jun 2020 22:44:26 -0500 Subject: [PATCH] chore: tidy --- packages/entity/trait/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/entity/trait/index.js b/packages/entity/trait/index.js index 025d3e0..4d81657 100644 --- a/packages/entity/trait/index.js +++ b/packages/entity/trait/index.js @@ -14,8 +14,8 @@ export class Trait extends decorate(class {}) { const ctor = this.constructor; this._fastDirtyCheck = true; this._memoizedListeners = undefined; - this.params = Object.assign({}, ctor.defaultParams(), params); - this.state = Object.assign({}, ctor.defaultState(), state); + this.params = ctor.defaultParamsWith(params); + this.state = ctor.defaultStateWith(state); this.previousState = JSON.parse(JSON.stringify(this.state)); if (this.tick) { this.tick = this.tick.bind(this); @@ -53,10 +53,18 @@ export class Trait extends decorate(class {}) { return {}; } + static defaultParamsWith(defaults) { + return {...this.defaultParams(), ...defaults}; + } + static defaultState() { return {}; } + static defaultStateWith(defaults) { + return {...this.defaultState(), ...defaults}; + } + static dependencies() { return []; }