Re: [whatwg/dom] Add ParentNode.prototype.replaceContents(nodes) (#755)

annevk commented on this pull request.

Thank you for starting on this so quickly! I think this needs a slightly different approach, which I've tried to outline inline. Basically what I'd like to see is for this to build upon the same primitive `innerHTML` and `textContent` use, but it'll need some additional checks as the input isn't necessary restricted to Text and Element nodes as it is with those APIs.

> @@ -2839,6 +2839,7 @@ interface mixin ParentNode {
 
   [CEReactions, Unscopable] void prepend((Node or DOMString)... nodes);
   [CEReactions, Unscopable] void append((Node or DOMString)... nodes);
+  [CEReactions, Unscopable] void replaceContents((Node or DOMString)... nodes);

I think per the discussion we ended up with `replaceChildren()` as a name, as "contents" doesn't always refer to nodes. Did I miss something?

> @@ -2878,6 +2879,15 @@ Element includes ParentNode;
   the <a>node tree</a> are violated.
   <!-- "NotFoundError" is impossible -->
 
+ <dt><code><var>node</var> . <a method for=ParentNode lt="replaceContents()">replaceContents</a>(<var>nodes</var>)</code>
+ <dd>
+  <p>Inserts <var>nodes</var> after the <a>last child</a> of <var>node</var>, while replacing

This needs rewording.

> @@ -2925,6 +2935,45 @@ must run these steps:
  <li><p><a>Append</a> <var>node</var> to <a>context object</a>.
 </ol>
 
+<p>The <dfn method for=ParentNode><code>replaceContents(<var>nodes</var>)</code></dfn> method, when invoked,
+must run these steps:
+
+<ol>
+  <li><a for=/>Remove</a> all
+  <var>parent</var>'s <a>children</a>, in
+  <a>tree order</a>, with the
+  <i>suppress observers flag</i> set.

I think we should strive to use the https://dom.spec.whatwg.org/#concept-node-replace-all primitive here, which would take care of most of the work, preceded by a call to https://dom.spec.whatwg.org/#converting-nodes-into-a-node.

And I guess we need to run https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity as well.

-- 
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/pull/755#pullrequestreview-227222588

Received on Tuesday, 16 April 2019 14:22:33 UTC