bikeshaving / crank

The Just JavaScript Framework
https://crank.js.org
MIT License
2.7k stars 75 forks source link

Turn DOM node reads of multiple DOM nodes into DocumentFragments #209

Closed brainkim closed 3 years ago

brainkim commented 3 years ago
function *Component() {
  while (true) {
    this.schedule((node) => {
      // currently node is an array of div elements, but it might be nicer to have node be a DocumentFragment element instead.
      console.log(node.querySelector("1").textContent); // => 1
    });
    yield (
      <Fragment>
        <div class="1">1</div>
        <div class="2">2</div>
        <div class="3">3</div>
      </Fragment>
    );
  }
}
brainkim commented 3 years ago

This probably won’t work because appending elements to a DocumentFragment will reparent the DOM nodes and remove them from the live DOM. I want something like https://github.com/whatwg/dom/issues/736 except the opposite, in that rather than persisting the fragment after its appended to the DOM, I want the nodes added to the DocumentFragment to be persisted in the DOM instead.