From f9d783e12b7a1ef65f7c9c0e0a024d4d63319f74 Mon Sep 17 00:00:00 2001 From: Hans Otto Wirtz Date: Tue, 31 Oct 2023 14:29:42 +0100 Subject: [PATCH] Fix preventChangePropagation --- package.json | 2 +- src/done-tracker-interface.ts | 2 ++ src/leaf-done-tracker.ts | 2 ++ src/node-done-tracker.ts | 17 ++++++++++------- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index c285def..666fc86 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-done-tracker", - "version": "0.0.15-beta.4", + "version": "0.0.15-beta.5", "description": "Keep track of when your React tree is done loading", "type": "module", "main": "./dist/index.js", diff --git a/src/done-tracker-interface.ts b/src/done-tracker-interface.ts index f18f712..44c6598 100644 --- a/src/done-tracker-interface.ts +++ b/src/done-tracker-interface.ts @@ -26,6 +26,8 @@ export interface DoneTracker { readonly erroredAt: number | null; readonly pendingAt: number; + readonly preventChangePropagation: boolean; + addEventListener(event: K, listener: DoneTrackerListener): void; removeEventListener(event: K, listener: DoneTrackerListener): void; diff --git a/src/leaf-done-tracker.ts b/src/leaf-done-tracker.ts index 663b852..64f5fec 100644 --- a/src/leaf-done-tracker.ts +++ b/src/leaf-done-tracker.ts @@ -16,6 +16,8 @@ export class LeafDoneTracker extends BaseDoneTracker implements DoneTracker { private _erroredAt: number | null = null; private _pendingAt: number = performance.now(); + public preventChangePropagation = false; + get id() { return this._name ? `${this._id}:${this._name}` : this._id; } diff --git a/src/node-done-tracker.ts b/src/node-done-tracker.ts index 346f279..d816779 100644 --- a/src/node-done-tracker.ts +++ b/src/node-done-tracker.ts @@ -18,13 +18,14 @@ export class NodeDoneTracker extends BaseDoneTracker implements DoneTracker { private _error: any = null; private _errorSource: DoneTracker | undefined; public skip = false; - public preventChangePropagation = false; private readonly _createdAt = performance.now(); private _doneAt: number | null = null; private _erroredAt: number | null = null; private _pendingAt: number = performance.now(); + public preventChangePropagation = false; + get id() { return this._name ? `${this._id}:${this._name}` : this._id; } @@ -130,12 +131,14 @@ export class NodeDoneTracker extends BaseDoneTracker implements DoneTracker { if (!canReset) return; this.reset(); }); - child.addEventListener("change", () => { - debug("Child of", this.id, "changed"); - if (!this.done) return; - if (this.preventChangePropagation) return; - this.dispatchEvent("change"); - }); + if (!child.preventChangePropagation) { + child.addEventListener("change", () => { + debug("Child of", this.id, "changed"); + if (!this.done) return; + // needs to be available for useDoneTrackerSubscription + this.dispatchEvent("change"); + }); + } if (child.done) { debug("Child was already done when added", child.id);