Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new mutation observer init options elementByAttributeFilter and elementFilter #885

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions dom.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3364,6 +3364,8 @@ dictionary MutationObserverInit {
boolean attributeOldValue;
boolean characterDataOldValue;
sequence<DOMString> attributeFilter;
sequence<DOMString> elementByAttributeFilter;
sequence<DOMString> elementFilter;
};
</pre>

Expand Down Expand Up @@ -3442,6 +3444,19 @@ dictionary MutationObserverInit {
<a>attribute</a> mutations need to be
observed and {{MutationObserverInit/attributes}} is true
or omitted.

<dt>{{MutationObserverInit/elementByAttributeFilter}}
<dd>Set to a list of <a>attribute</a>
<a for=Attr>local names</a> (without <a for=Attr>namespace</a>) to observe changes
to the presence of an elements <a>attributes</a>.

<dt>{{MutationObserverInit/elementFilter}}
<dd>Set to a list of <a for=/>element</a>
<a for=Element>local names</a> (without <a for=Attr>namespace</a>) to observe
changes to the presence of specific <a for=/>element</a> <a for=Element>local names</a>
if not all <a for=/>element</a> <a for=Element>local names</a> need to be
observed and {{MutationObserverInit/attributes}} is true
or omitted.
</dl>

<dt><code><var>observer</var> . {{disconnect()}}</code>
Expand Down Expand Up @@ -3479,6 +3494,14 @@ method steps are:
<a for=map>exist</a>, then set <var>options</var>["{{MutationObserverInit/characterData}}"] to
true.

<li><p>If <var>options</var>'s {{MutationObserverInit/elementByAttributeFilter}} is present and
<var>options</var>'s {{MutationObserverInit/childList}} is omitted, then set
<var>options</var>'s {{MutationObserverInit/childList}} to true.

<li><p>If <var>options</var>'s {{MutationObserverInit/elementFilter}} is present and
<var>options</var>'s {{MutationObserverInit/childList}} is omitted, then set
<var>options</var>'s {{MutationObserverInit/childList}} to true.

<li><p>If none of <var>options</var>["{{MutationObserverInit/childList}}"],
<var>options</var>["{{MutationObserverInit/attributes}}"], and
<var>options</var>["{{MutationObserverInit/characterData}}"] is true, then <a>throw</a> a
Expand All @@ -3496,6 +3519,14 @@ method steps are:
<var>options</var>["{{MutationObserverInit/characterData}}"] is false, then <a>throw</a> a
<code>TypeError</code>.

<li><p>If <var>options</var>'s {{MutationObserverInit/elementByAttributeFilter}} is present and
<var>options</var>'s {{MutationObserverInit/childList}} is false, then <a>throw</a> a
<code>TypeError</code>.

<li><p>If <var>options</var>'s {{MutationObserverInit/elementFilter}} is present and
<var>options</var>'s {{MutationObserverInit/childList}} is false, then <a>throw</a> a
<code>TypeError</code>.

<li>
<p><a for=list>For each</a> <var>registered</var> of <var>target</var>'s
<a>registered observer list</a>, if <var>registered</var>'s
Expand Down Expand Up @@ -3635,6 +3666,67 @@ method steps are:
<ol>
<li><p>Assert: either <var>addedNodes</var> or <var>removedNodes</var> <a for=set>is not empty</a>.

<li>
<p>If either <var>options</var>'s' {{MutationObserverInit/elementFilter}} or
{{MutationObserverInit/elementByAttributeFilter}} is present, then:

<ol>
<li><p>Let <var>filteredAddedNodes</var> be an empty <a for=/>list</a>.

<li><p>Let <var>filterRemovedNodes</var> be an empty <a for=/>list</a>.

<li>
<p>For each <var>node</var> in <var>addedNodes</var></a>:

<ol>
<li><p>Let <var>nodeAttributesList</var> be the set of <a for=Attr>local name</a>s of <var>node</var>'s
<a>attribute</a>s.

<li>
<p>If none of the following are true

<ul class=brief>
<li><var>options</var>'s {{MutationObserverInit/elementFilter}} is present, and the
<a>node</a>'s <var>localName</var> is in {{MutationObserverInit/elementFilter}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite confusing. Isn't node the variable and local name the field?


<li><var>options</var>'s {{MutationObserverInit/elementByAttributeFilter}} is present, and
<var>options</var>'s {{MutationObserverInit/elementByAttributeFilter}} contains any of the
attribute name in <var>nodeAttributesList</var>
</ul>

<p>then <a for=list>append</a> <var>node</var> to <var>filteredAddedNodes</var>.
</ol>

<li>
<p>For each <var>node</var> in <var>removedNodes</var></a>:

<ol>
<li><p>Let <var>nodeAttributesList</var> be the set of <a for=Attr>local name</a>s of <var>node</var>'s
<a>attribute</a>s.

<li>
<p>If none of the following are true

<ul class=brief>
<li><var>options</var>'s {{MutationObserverInit/elementFilter}} is present, and the
<a>node</a>'s <var>localName</var> is in {{MutationObserverInit/elementFilter}}

<li><var>options</var>'s {{MutationObserverInit/elementByAttributeFilter}} is present, and
<var>options</var>'s {{MutationObserverInit/elementByAttributeFilter}} contains any of the
attribute names in <var>nodeAttributesList</var>
</ul>

<p>then <a for=list>append</a> <var>node</var> to <var>filterRemovedNodes</var>.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must be confused here.
Don't we want something like
if elementFilter is present, and elementByAttributeFilter is not present and localName is in elementfilter, or if
elementByAttributeFilter is present and elementFilter is not present and elementByAttributeFilter contains any of the attribute names in nodeAttribute list ... or combination of those two

</ol>

<li><p>Assert: either <var>filteredAddedNodes</var> or <var>filteredRemovedNodes</var>
<a for=set>is not empty</a>.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we assert this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these are now defined in scope. Check if filteredAddedNodes length > 0 or filteredRemovedNodes length > 0.


<li><p>Set <var>addedNodes</var> to <var>filteredAddedNodes</var>

<li><p>Set <var>removedNodes</var> to <var>filteredRemovedNodes</var>
</ol>

<li><p><a>Queue a mutation record</a> of "<code>childList</code>" for <var>target</var> with
null, null, null, <var>addedNodes</var>, <var>removedNodes</var>, <var>previousSibling</var>,
and <var>nextSibling</var>.
Expand Down