-
Notifications
You must be signed in to change notification settings - Fork 60
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
Fixing connected, insert, & remove stuff #446
Changes from all commits
65a7329
7634d8f
325ed2d
aea907e
50568e5
aab5259
29a6c4d
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@remote-dom/polyfill': patch | ||
--- | ||
|
||
Ensure that the insert and remove hooks are only called for element parents. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@remote-dom/polyfill': patch | ||
--- | ||
|
||
Make connectedCallback and disconnectedCallback call on connect/disconnect recursively |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@remote-dom/polyfill': minor | ||
--- | ||
|
||
Implement node.isConnected |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import {DATA, OWNER_DOCUMENT, ATTRIBUTES, NodeType} from './constants.ts'; | ||
import { | ||
DATA, | ||
OWNER_DOCUMENT, | ||
ATTRIBUTES, | ||
NodeType, | ||
CHILD, | ||
NEXT, | ||
} from './constants.ts'; | ||
import type {Document} from './Document.ts'; | ||
import type {DocumentFragment} from './DocumentFragment.ts'; | ||
import type {Node} from './Node.ts'; | ||
|
@@ -78,3 +85,23 @@ export function cloneNode( | |
return cloned; | ||
} | ||
} | ||
|
||
export function descendants(node: Node) { | ||
const nodes: Node[] = []; | ||
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. Could we take this extraction as a time to switch this to return an iterator instead? 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. I thought the same, but iterators are pretty bad in terms of performance, and my gut feeling is that the performance could matter in this case. 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. https://jsperf.app/dedosu - quick performance test for this. Iterators are about half speed in Chrome, but much slower in Safari and Firefox. It might not matter much in reality. The advantage of the iterator is early breaking, but we don't have that need yet. |
||
const walk = (node: Node) => { | ||
nodes.push(node); | ||
const child = node[CHILD]; | ||
if (child) walk(child); | ||
const sibling = node[NEXT]; | ||
if (sibling) walk(sibling); | ||
}; | ||
const child = node[CHILD]; | ||
if (child) walk(child); | ||
return nodes; | ||
} | ||
|
||
export function selfAndDescendants(node: Node) { | ||
const nodes = descendants(node); | ||
nodes.unshift(node); | ||
return nodes; | ||
} |
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.
@lemonmade this is required for custom elements within the root to fire
connectedCallback
.