From c1e7db9ebfd4d1e1077555955647e9dde778a1f8 Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 18 Mar 2019 20:03:30 -0500 Subject: [PATCH] feat: more intelligent trait state merging --- packages/entity/trait.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/entity/trait.js b/packages/entity/trait.js index e165d3e..8ff9b7b 100644 --- a/packages/entity/trait.js +++ b/packages/entity/trait.js @@ -11,7 +11,17 @@ export class Trait { } acceptStateChange(change) { - this.state = this.state.merge(change); + const undefinedProperties = {}; + for (const key in change) { + const value = change[key]; + if (key in this.entity) { + this.entity[key] = value; + } + else { + undefinedProperties[key] = value; + } + } + this.state = this.state.merge(undefinedProperties); } actions() {