From 7d1346746fd245042d6de8a94bceb39e6a977d4c Mon Sep 17 00:00:00 2001 From: thepaperpilot Date: Sun, 17 Jul 2022 19:27:53 -0500 Subject: [PATCH] Fix trackResetTime not working after the layer is removed and re-added --- src/features/reset.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/features/reset.ts b/src/features/reset.ts index d3b373b..3a724e3 100644 --- a/src/features/reset.ts +++ b/src/features/reset.ts @@ -69,8 +69,13 @@ export function createReset( const listeners: Record = {}; export function trackResetTime(layer: BaseLayer, reset: GenericReset): Persistent { const resetTime = persistent(new Decimal(0)); - listeners[layer.id] = layer.on("preUpdate", diff => { - resetTime.value = Decimal.add(resetTime.value, diff); + globalBus.on("addLayer", layerBeingAdded => { + if (layer === layerBeingAdded) { + listeners[layer.id]?.(); + listeners[layer.id] = layer.on("preUpdate", diff => { + resetTime.value = Decimal.add(resetTime.value, diff); + }); + } }); globalBus.on("reset", currentReset => { if (currentReset === reset) {