Skip to content

Commit

Permalink
Fix preventChangePropagation
Browse files Browse the repository at this point in the history
  • Loading branch information
hansottowirtz committed Oct 31, 2023
1 parent 2cbaa15 commit f9d783e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/done-tracker-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface DoneTracker {
readonly erroredAt: number | null;
readonly pendingAt: number;

readonly preventChangePropagation: boolean;

addEventListener<K extends keyof DoneTrackerEventMap>(event: K, listener: DoneTrackerListener<K>): void;

removeEventListener<K extends keyof DoneTrackerEventMap>(event: K, listener: DoneTrackerListener<K>): void;
Expand Down
2 changes: 2 additions & 0 deletions src/leaf-done-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 10 additions & 7 deletions src/node-done-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down

1 comment on commit f9d783e

@vercel
Copy link

@vercel vercel bot commented on f9d783e Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.