-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issues with descendants
and allDescendants
#3728
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,6 +199,7 @@ export class RecordSet { | |
this.store.logDebug(`Attempted to remove non-existent record: ${id}`); | ||
return; | ||
} | ||
allRemoves.add(id); | ||
this.gatherDescendantIds(id, allRemoves); | ||
}); | ||
allRemoves.forEach(it => newRecords.delete(it)); | ||
|
@@ -273,14 +274,13 @@ export class RecordSet { | |
} | ||
|
||
private gatherDescendantIds(id: StoreRecordId, idSet: Set<StoreRecordId>): Set<StoreRecordId> { | ||
if (!idSet.has(id)) { | ||
idSet.add(id); | ||
const children = this.childrenMap.get(id); | ||
if (children) { | ||
children.forEach(child => this.gatherDescendantIds(child.id, idSet)); | ||
this.childrenMap.get(id)?.forEach(child => { | ||
if (!idSet.has(child.id)) { | ||
// paranoia? did we encounter loops? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this came in a while ago with a big refactor that introduced many of these recordset APIs - doesn't look like a response to a particular bug or use case. https://github.com/xh/hoist-react/pull/1082/files (FWIW - I'd still vote to carry it forward - will cop to a certain amount of paranoia in these classes myself) |
||
idSet.add(child.id); | ||
this.gatherDescendantIds(child.id, idSet); | ||
} | ||
} | ||
|
||
}); | ||
return idSet; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah interesting - there is a chance there is some code out there that was depending on the prior behavior (intentionally or not), but hard to argue that it was correct. This looks like the right choice / fix to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that this change makes sense - previous behavior was definitely confusing - I vaguely remember this from when we were re-working these methods way back but can't remember why we included the record in the list of descendants