From b713210b0c4661a3964ecc7cc18933dcc1579884 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 3 Mar 2017 05:28:21 -0700 Subject: [PATCH] Emit didUpdateDecorations events synchronously The rendering layer can be asynchronous instead, plus layer decorations should remove the need to emit lots of individual events. --- src/decoration-manager.js | 32 +++++++------------------------- src/decoration.coffee | 4 ++-- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/src/decoration-manager.js b/src/decoration-manager.js index f9e31e60d..dbaa68c8b 100644 --- a/src/decoration-manager.js +++ b/src/decoration-manager.js @@ -8,8 +8,6 @@ class DecorationManager { this.displayLayer = displayLayer this.emitter = new Emitter - this.didUpdateDecorationsEventScheduled = false - this.updatedSynchronously = false this.decorationsById = {} this.decorationsByMarkerId = {} this.overlayDecorationsById = {} @@ -35,10 +33,6 @@ class DecorationManager { return this.emitter.on('did-update-decorations', callback) } - setUpdatedSynchronously(updatedSynchronously) { - this.updatedSynchronously = updatedSynchronously - } - decorationForId(id) { return this.decorationsById[id] } @@ -171,7 +165,7 @@ class DecorationManager { } this.decorationsById[decoration.id] = decoration this.observeDecoratedLayer(marker.layer) - this.scheduleUpdateDecorationsEvent() + this.emitDidUpdateDecorations() this.emitter.emit('did-add-decoration', decoration) return decoration } @@ -186,7 +180,7 @@ class DecorationManager { } this.layerDecorationsByMarkerLayerId[markerLayer.id].push(decoration) this.observeDecoratedLayer(markerLayer) - this.scheduleUpdateDecorationsEvent() + this.emitDidUpdateDecorations() return decoration } @@ -194,20 +188,8 @@ class DecorationManager { return this.decorationsByMarkerId[markerId] } - scheduleUpdateDecorationsEvent() { - if (this.updatedSynchronously) { - this.emitter.emit('did-update-decorations') - return - } - - if (!this.didUpdateDecorationsEventScheduled) { - this.didUpdateDecorationsEventScheduled = true - return process.nextTick(() => { - this.didUpdateDecorationsEventScheduled = false - return this.emitter.emit('did-update-decorations') - } - ) - } + emitDidUpdateDecorations() { + this.emitter.emit('did-update-decorations') } decorationDidChangeType(decoration) { @@ -234,7 +216,7 @@ class DecorationManager { delete this.overlayDecorationsById[decoration.id] this.unobserveDecoratedLayer(marker.layer) } - return this.scheduleUpdateDecorationsEvent() + return this.emitDidUpdateDecorations() } didDestroyLayerDecoration(decoration) { @@ -250,7 +232,7 @@ class DecorationManager { } this.unobserveDecoratedLayer(markerLayer) } - return this.scheduleUpdateDecorationsEvent() + return this.emitDidUpdateDecorations() } observeDecoratedLayer(layer) { @@ -258,7 +240,7 @@ class DecorationManager { this.decorationCountsByLayerId[layer.id] = 0 } if (++this.decorationCountsByLayerId[layer.id] === 1) { - this.layerUpdateDisposablesByLayerId[layer.id] = layer.onDidUpdate(this.scheduleUpdateDecorationsEvent.bind(this)) + this.layerUpdateDisposablesByLayerId[layer.id] = layer.onDidUpdate(this.emitDidUpdateDecorations.bind(this)) } } diff --git a/src/decoration.coffee b/src/decoration.coffee index 19d029f76..5d406e17c 100644 --- a/src/decoration.coffee +++ b/src/decoration.coffee @@ -150,7 +150,7 @@ class Decoration @properties = translateDecorationParamsOldToNew(newProperties) if newProperties.type? @decorationManager.decorationDidChangeType(this) - @decorationManager.scheduleUpdateDecorationsEvent() + @decorationManager.emitDidUpdateDecorations() @emitter.emit 'did-change-properties', {oldProperties, newProperties} ### @@ -175,5 +175,5 @@ class Decoration @properties.flashCount++ @properties.flashClass = klass @properties.flashDuration = duration - @decorationManager.scheduleUpdateDecorationsEvent() + @decorationManager.emitDidUpdateDecorations() @emitter.emit 'did-flash'