From ed33d9c90d4cb4f4f5cf6e62719a03db6ffb9400 Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 2 May 2019 22:18:30 -0500 Subject: [PATCH] perf: remove extraneous check --- packages/graphics/traits/visible.trait.js | 35 ++++++++--------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/packages/graphics/traits/visible.trait.js b/packages/graphics/traits/visible.trait.js index 09b4733..fb4cab7 100644 --- a/packages/graphics/traits/visible.trait.js +++ b/packages/graphics/traits/visible.trait.js @@ -94,13 +94,6 @@ export class Visible extends decorate(Trait) { this.entity.visibleScale = I.List(scale); } - shouldSynchronizePosition() { - if (!this._container) { - return false; - } - return this._container && this.trackPosition; - } - synchronizePosition() { if (!this.entity.is('positioned')) { return; @@ -133,7 +126,7 @@ export class Visible extends decorate(Trait) { } listeners() { - const listeners = { + return { isVisibleChanged: () => { if (!this._container) { @@ -153,6 +146,16 @@ export class Visible extends decorate(Trait) { this.translateVisibleAabb(); }, + traitAdded: (type) => { + if (-1 === [ + 'visible', + 'positioned', + ].indexOf(type)) { + return; + } + this.synchronizePosition(); + }, + visibleScaleChanged: () => { const scale = this.entity.visibleScale; this._visibleScale = [scale.get(0), scale.get(1)]; @@ -163,18 +166,6 @@ export class Visible extends decorate(Trait) { }, }; - if (this.shouldSynchronizePosition()) { - listeners.traitAdded = (type) => { - if (-1 === [ - 'visible', - 'positioned', - ].indexOf(type)) { - return; - } - this.synchronizePosition(); - }; - } - return listeners; } methods() { @@ -188,9 +179,7 @@ export class Visible extends decorate(Trait) { } renderTick(elapsed) { - if (this.shouldSynchronizePosition()) { - this.synchronizePosition(); - } + this.synchronizePosition(); } translateVisibleAabb() {