Skip to content

Commit

Permalink
Use a queue of deferred steps in the node insertion algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Feb 8, 2019
1 parent 55b4dbb commit da96f99
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2389,12 +2389,10 @@ of a <var>node</var> into a <var>parent</var> before a <var>child</var>, run the
</ol>

<p><a lt="Other applicable specifications">Specifications</a> may define
<dfn export id=concept-node-insert-ext>insertion steps</dfn> for all or some <a for=/>nodes</a>. The
algorithm is passed <var ignore>insertedNode</var>, as indicated in the <a for=/>insert</a>
algorithm below.
<!-- See https://github.com/whatwg/dom/issues/34#issuecomment-125571750 for why we might need to
adjust this further based on the requirements of the script element. There might be other ways
to define that though as Olli suggests, so leaving that out for now. -->
<dfn export id=concept-node-insert-ext>insertion steps</dfn> or
<dfn export id=concept-node-children-added>children added steps</dfn> for all or some
<a for=/>nodes</a>. The two algorithms are passed <var ignore>insertedNode</var> and
<var ignore>deferredStepsQueue</var>, as indicated in the <a for=/>insert</a> algorithm below.

<p>To <dfn export id=concept-node-insert>insert</dfn> a <var>node</var> into a <var>parent</var>
before a <var>child</var>, with an optional <i>suppress observers flag</i>, run these steps:
Expand Down Expand Up @@ -2440,8 +2438,12 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
<li><p>Let <var>previousSibling</var> be <var>child</var>'s <a>previous sibling</a> or
<var>parent</var>'s <a>last child</a> if <var>child</var> is null.

<li><p>Let <var>deferredStepsQueue</var> be the empty <a>queue</a>.

<li><p>Let <var>textChanged</var> be false.

<li>
<p>For each <var>node</var> in <var>nodes</var>, in <a>tree order</a>:
<p>For each <var>node</var> in <var>nodes</var>:

<ol>
<li><p>If <var>child</var> is null, then <a for=set>append</a> <var>node</var> to
Expand All @@ -2453,8 +2455,7 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
<li><p>If <var>parent</var> is a <a for=Element>shadow host</a> and <var>node</var> is a
<a>slotable</a>, then <a>assign a slot</a> for <var>node</var>.

<li>If <var>node</var> is a {{Text}} node, run the <a>child text content change steps</a> for
<var>parent</var>.
<li>If <var>node</var> is a {{Text}} node, set <var>textChanged</var> to true.

<li><p>If <var>parent</var>'s <a for=tree>root</a> is a <a for=/>shadow root</a>, and
<var>parent</var> is a <a>slot</a> whose <a for=slot>assigned nodes</a> is the empty list,
Expand All @@ -2467,7 +2468,8 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
<var>node</var>, in <a>shadow-including tree order</a>:

<ol>
<li><p>Run the <a>insertion steps</a> with <var>inclusiveDescendant</var>.
<li><p>Run the <a>insertion steps</a> with <var>inclusiveDescendant</var> and
<var>deferredStepsQueue</var>.

<li>
<p>If <var>inclusiveDescendant</var> is <a>connected</a>, then:
Expand All @@ -2490,6 +2492,22 @@ before a <var>child</var>, with an optional <i>suppress observers flag</i>, run
</li>
</ol>

<li><p>If <var>textChanged</var> is true, run the <a>child text content change steps</a> for
<var>parent</var>.

<li><p>If <var>nodes</var> is not empty, run the <a>children added steps</a> with
<var>parent</var> and <var>deferredStepsQueue</var>.

<li>
<p>While <var>deferredStepsQueue</var> is not empty:

<ol>
<li><p>Let <var>deferredSteps</var> be the result of <a for=queue>dequeueing</a>
<var>deferredStepsQueue</var>.

<li><p>Run <var>deferredSteps</var>.
</ol>

<li><p>If <i>suppress observers flag</i> is unset, then <a>queue a tree mutation record</a> for
<var>parent</var> with <var>nodes</var>, « », <var>previousSibling</var>, and <var>child</var>.
</ol>
Expand Down

0 comments on commit da96f99

Please sign in to comment.