-
Notifications
You must be signed in to change notification settings - Fork 297
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
base: main
Are you sure you want to change the base?
Add new mutation observer init options elementByAttributeFilter and elementFilter #885
Conversation
624f14f
to
020ee4a
Compare
@AndrewRot can Shape Security sign https://participate.whatwg.org/agreement? Previously that ended up not happening, but not sure what the reason was. |
e37b25c
to
19960d9
Compare
This comment has been minimized.
This comment has been minimized.
…elementLocalNameFilter
d00431a
to
d1c9cb6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally this looks great, thanks for working on this! I have left a couple of formatting nits and I'm happy to help with those once we're further along.
We'll need a lot of tests to cover the various conditions and new behavior of observe()
.
I'm a little concerned about the agreement. Typically a person in a management or a very senior engineer would sign it (or at least be an alternate), but neither appears to be the case here, assuming I have interpreted your title correctly. As it seems this is a very big company, have legal et al signed off on this?
dom.bs
Outdated
{{MutationObserverInit/elementFilterByAttribute}} is present, then: | ||
|
||
<ol> | ||
<li><p>Let <var>nodeAttributesList</var> be the set of local names of node's attributes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is node referring to here? I feel like this is lacking some references to other variables.
dom.bs
Outdated
@@ -3594,6 +3625,60 @@ run these steps: | |||
<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/elementLocalNameFilter}} or | |||
{{MutationObserverInit/elementFilterByAttribute}} is present, then: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this <p>
isn't the only child of the <li>
, it needs to be on its own line, indented one. This also goes for the following <ol>
, which is not indented accurately.
dom.bs
Outdated
<li> | ||
<p>For each <var>node</var> in <var>addedNodes</var></a>. | ||
|
||
<li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect a for each to be followed by a nested list so there's an <ol>
missing here I think.
dom.bs
Outdated
<p>If none of the following are true | ||
|
||
<ul class=brief> | ||
<li>if <var>options</var>'s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/if// I think? Same below. If not I'd try to reword these to be more clearly true/false statements.
dom.bs
Outdated
<ul class=brief> | ||
<li>if <var>options</var>'s | ||
{{MutationObserverInit/elementLocalNameFilter}} is present, and | ||
"<code>node.localName</code>" is in {{MutationObserverInit/elementLocalNameFilter}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is node.localName and why is it formatted this way? Is that a special value?
@mfreed7 any thoughts from Google on this? |
FWIW, we're supportive of this proposal. |
@annevk yes - I've gotten written approval to sign off on the agreement from our legal department as well as my team managers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for confirming the IPR stuff, that's great! There's a couple things remaining with the PR (note that several comments apply to multiple places) and the other thing we'll need here are tests. Do you think you can work on those?
dom.bs
Outdated
|
||
<ol> | ||
<li><p>Let <var>nodeAttributesList</var> be the set of local names of <var>node</var>'s | ||
attributes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"local names" and "attributes" should xref the relevant definitions. (We should also have a test with two attributes that have the same local name and see if this is all working as designed.)
dom.bs
Outdated
<p>If none of the following are true | ||
|
||
<ul class=brief> | ||
<li>if <var>options</var>'s {{MutationObserverInit/elementFilter}} is present, and the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the nested "if" works here. This needs rephrasing.
|
||
<ul class=brief> | ||
<li>if <var>options</var>'s {{MutationObserverInit/elementFilter}} is present, and the | ||
<a>node</a>'s <var>localName</var> is in {{MutationObserverInit/elementFilter}} |
There was a problem hiding this comment.
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?
dom.bs
Outdated
attribute name in <var>nodeAttributesList</var> | ||
</ul> | ||
|
||
<p>then <a for=queue>enqueue</a> <var>record</var> node in <var>filteredAddedNodes</var>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might mean <a for=list>append</a> <var>node</var> to <var>filteredAddedNodes</var>
here?
@annevk looks like agreement was filled out. Though I just added my manager as a secondary contact. All comments appear to have been addressed. At this point, the only thing missing seems to be the tests? I can start on those. |
@AndrewRot that sounds great, thank you! Once the tests are there I'm happy to give this another pass. |
Has there been any progress on the tests? I'm working on a product which would benefit from this Mutation Observer filter feature, and might be able to assist with tests if there is interest. |
@mfreed7 ping on Chromium interest. @smaug---- Gecko? @bershanskiy I'd be happy to pick up the remaining specification work assuming @AndrewRot no longer has the bandwidth if you can sort the tests. Thanks for volunteering! |
Hi @bershanskiy & @annevk - I'm glad this feature is useful for others! Yes, feel free to take the reins from here. I do not currently have the bandwidth to allocate for this feature. |
</ol> | ||
|
||
<li><p>Assert: either <var>filteredAddedNodes</var> or <var>filteredRemovedNodes</var> | ||
<a for=set>is not empty</a>. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
attribute names in <var>nodeAttributesList</var> | ||
</ul> | ||
|
||
<p>then <a for=list>append</a> <var>node</var> to <var>filterRemovedNodes</var>. |
There was a problem hiding this comment.
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
Gecko would implement this or some variant of it. |
Looks like a good addition to |
Adds additional options when constructing a
MutationObserver
.MutationObserverInit now contains two additional options:
elementByAttributeFilter
andelementFilter
which are used to enhance the precision of filtering DOM nodes to observe.See #398 for the background.
(See WHATWG Working Mode: Changes for more details.)
Preview | Diff