Refactor: move getRealChildNodes and getRealChildren to core#34813
Refactor: move getRealChildNodes and getRealChildren to core#34813samouri merged 6 commits intoampproject:mainfrom
Conversation
|
Hey @jridgewell! These files were changed: |
rcebulko
left a comment
There was a problem hiding this comment.
Looks good! Related tests should join test-query.js instead of test-dom.js, but otherwise approving to unblock
| const nodes = element.getRealChildNodes | ||
| ? element.getRealChildNodes() | ||
| : toArray(element.childNodes); | ||
| const nodes = realChildNodes(element); |
There was a problem hiding this comment.
Would this change handle a basic Element less efficiently since it's not using the built-in iterator here?
There was a problem hiding this comment.
Thats a good question! I don't know why the underlying realChildNodes isn't directly using element.childNodes, since it seems to be attempting to do the same thing. @jridgewell do you know?
There was a problem hiding this comment.
It looks like this is checking whether getRealNodes is defined, ie "Is this a CustomElement? If so, use our helper to get the real children, otherwise it's an ordinary element and we should use its children because they're all "real""
There was a problem hiding this comment.
Definitely what it is doing. My question is: "why does childNodes exist as a helper".
Lines 250 to 265 in c88b275
Can we replace it with toArray(node.childNodes).filter(callback) Or iterate through el.childNodes directly
There was a problem hiding this comment.
From further investigation, this is only used in two places. Will remove it entirely in a followup PR.
| node.hasAttribute('overflow')) | ||
| ) { | ||
| return true; | ||
| if (node.nodeType !== Node.ELEMENT_NODE) { |
There was a problem hiding this comment.
…ebook-like-bento-version * 'main' of github.com:ampproject/amphtml: (23 commits) `amp-story-desktop-one-panel` Update demo with usecases (ampproject#34867) 🚮 Remove src/purifier.js rollup config (ampproject#34876) Validator Rollup (ampproject#34769) ✨ `amp-story-desktop-one-panel` Check UI type to get page dimension on tap (ampproject#34875) Refactor: move getRealChildNodes and getRealChildren to core (ampproject#34813) 🏗📖 Fix some example files that do not validate (ampproject#34835) 🏗Add `#test` and `#testing` to alias list (ampproject#34853) Add css files for missing components (ampproject#34861) Apply bulk transform to html tags (ampproject#34836) 🐛 amp-ima-video: Fix duration label on livestreams (ampproject#34865) ♻️ Extract `applyFillContent` into a standalone function (ampproject#34858) Give script tag closing tag (ampproject#34832) 🏗 Refinements to renovate config (ampproject#34862) Bento: Enable `SocialShare` for npm publishing (ampproject#34817) 🏗 Use aliased paths in generated extensions (ampproject#34860) ✨ `amp-story-desktop-one-panel` Position distance="2" page below viewport (ampproject#34834) 🏗 Set `wrapper` on generated Bento extensions (ampproject#34843) 🧪[story-ads] Allow viewer to set progress bar segment experiment. (ampproject#34827) 🏗 Allow extension bundles to specify their own wrapper (ampproject#34845) 🏗🚀 Speed up validated example grouping ~45x (ampproject#34837) ...
summary
In order to remove Runtime dependencies from
amp-layout'sbuildCallback, I've extracted getRealChildNodes and getRealChildren to core from CE and BE.The primary diff in most files looks like this:
Note: I've noticed that in the transition from classic to bento, we are making lots of small tradeoffs that reduce our reliance on runtime code (v0.js) and will end up duplicated in all of the extensions. It is definitely a worthwhile tradeoff, but at some point far in the future may be worth mitigating.