Skip to content
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

Explicitly update the child's parent #1221

Closed
TomokiMiyauci opened this issue Aug 27, 2023 · 2 comments
Closed

Explicitly update the child's parent #1221

TomokiMiyauci opened this issue Aug 27, 2023 · 2 comments

Comments

@TomokiMiyauci
Copy link

In the current specification, updating a child's parent reference is implicit and does not seem to be described anywhere.

For example, in appendChild, the parent's children are explicitly modified by insert.

  1. If child is null, then append node to parent's children.
  2. Otherwise, insert node into parent's children before child's index.

Somewhere before or after this, the appended node's parent reference should also be updated, but this is implicit.

When is the appropriate time for this?

@pshaughn
Copy link

"Parent reference" isn't a concept in the spec. The parent-child relationship is defined in https://dom.spec.whatwg.org/#trees ; if X is a child of Y, then Y by definition is a parent of X. When your implementation is using a two-way pair of references as an implementation detail of tracking this relationship, it probably should set them both at the same time.

@TomokiMiyauci
Copy link
Author

An object that participates in a tree has a parent, which is either null or an object, and has children,

I thought this expression meant that each node has an internal slot of parent and children.
But, certainly the word "associated" was not used.

The question has been answered. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants