Re: [whatwg/dom] Suggestion: new method - getNodesByType (#992)

> they do require extensive boilerplate

is that true though?

```js
function* getNodesByType(root, nodeType) {
    const iterator = document.createTreeWalker(root, nodeType);
    let node;
    while (node = iterator.nextNode())
      yield node;
}
```

You can use it like this:

```js
for (const node of getNodesByType(document, NodeFilter.SHOW_TEXT))
  console.log(node);
```

You can pass multiple filters too: `NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT`

The implementation in core will be pretty much the same of an iterator or a tree walker, so why is this method really needed?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/992#issuecomment-866789137

Received on Wednesday, 23 June 2021 12:23:18 UTC