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 elementHasAttributeNameFilter and elementLocalNameFilter to MutationObserver options #1

Open
wants to merge 51 commits into
base: master
Choose a base branch
from

Conversation

AndrewRot
Copy link
Owner

@AndrewRot AndrewRot commented Mar 26, 2020

Adds additional options when constructing a MutationObserver.

MutationObserverInit now contains two additional options: elementHasAttributeNameFilter and elementLocalNameFilter which are used to enhance the precision of filtering DOM nodes to observe.

See whatwg#398 for the background.

@@ -3437,6 +3450,14 @@ method, when invoked, must run these steps:
<var>options</var>'s {{MutationObserverInit/characterData}} is omitted, then set
<var>options</var>'s {{MutationObserverInit/characterData}} to true.

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

Choose a reason for hiding this comment

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

Remind me why we decided that childList should be set to true when either of these options are enabled. I think it's ok to just throw typeError, no?

Copy link
Owner Author

Choose a reason for hiding this comment

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

It implicitly defaults to checking the immediate node's childList. Otherwise it's a bit wonky to have to set elementHasAttributeNameFilter and set childList to true every time you want to use elementHasAttributeNameFilter

dom.bs Outdated
{{MutationObserverInit/elementHasAttributeFilter}} is present, then:

<ol>
<li><p>Let <var>nodeAttributesList</var> be <var>nodeAttributesList</var> of the node's attributes, "<code>node.attributes.keys</code>".

Choose a reason for hiding this comment

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

node.attribute.keys may not be accurate. Try to find the appropriate API to capture the attributeNames of a node.

Copy link
Owner Author

@AndrewRot AndrewRot Jul 24, 2020

Choose a reason for hiding this comment

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

Possibly element.getAttributeNames: https://developer.mozilla.org/en-US/docs/Web/API/Element/getAttributeNames however, this is on element, not node

Seems like element.getAttributeNames() is rather new-ish. Not sure if there is a preference on choosing APIs or code that is more backwards compatible.

Should I use the handy API getAttributeNames, or in the code block, write the polyfill code for it?

dom.bs Outdated

<li><var>options</var>'s {{MutationObserverInit/elementHasAttributeFilter}} is
present,and <var>options</var>'s {{MutationObserverInit/elementHasAttributeFilter}}
contains any of the attributes in <var>nodeAttributesList</var>

Choose a reason for hiding this comment

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

attributes ==> attribute names

dom.bs Outdated
@@ -3398,6 +3398,19 @@ dictionary MutationObserverInit {
<a>attribute</a> mutations need to be
observed and {{MutationObserverInit/attributes}} is true
or omitted.

<dt>{{MutationObserverInit/elementHasAttributeFilter}}

Choose a reason for hiding this comment

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

We are filtering based on just attribute names, right? So, shouldn't it just be elementHasAttributeNameFilter ?

dom.bs Outdated
"<code>node.localName</code>" is in {{MutationObserverInit/elementLocalNameFilter}}
<li>if <var>options</var>'s
{{MutationObserverInit/elementHasAttributeFilter}} is present,and <var>options</var>'s
{{MutationObserverInit/elementHasAttributeFilter}} contains any of the attributes

Choose a reason for hiding this comment

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

attribute names

@AndrewRot AndrewRot changed the title Add elementHasAttributeFilter and elementLocalNameFilter to MutationObserver options Add elementHasAttributeNameFilter and elementLocalNameFilter to MutationObserver options Jul 24, 2020
@AndrewRot AndrewRot force-pushed the new-mutation-observer-init-options branch from 624f14f to 020ee4a Compare August 12, 2020 22:34
@AndrewRot AndrewRot force-pushed the new-mutation-observer-init-options branch from e37b25c to 19960d9 Compare August 28, 2020 16:20
@AndrewRot AndrewRot force-pushed the new-mutation-observer-init-options branch from d00431a to d1c9cb6 Compare August 31, 2020 16:03
annevk and others added 12 commits September 2, 2020 10:41
This is for use with whatwg/html#5912, which
restricts access to ElementInternals's shadowRoot property for shadow
roots which were pre-existing before a custom element
upgrade/construction. See the discussion in
WICG/webcomponents#871 (comment)
for more context.
Now that the relevant W3C documents redirect here, there is no need to explain the differences with them. The Historical section now details what has been removed, without acknowledging the historical organization of those features.
Now that the default semantics are to throw, we need to be more explicit about catching.
chansuke and others added 26 commits November 18, 2020 11:07
It needs to pass this rather than an undefined variable. Also clean up the algorithm a bit.

Fixes whatwg#921.
Once you have thrown for all QName cases, you can no longer throw for Name cases. Tested as part of whatwg#423.

Also cleanup createElementNS()'s domintro.

Fixes whatwg#671 and closes whatwg#675.
This comma got dropped in 83037a1 but
the sentence isn’t grammatical without it, so this change restores it.
In particular adopt the getter/setter/method/constructor steps pattern.
Mainly to make the document more consistent which should make it easier to change going forward.
It has been deprecated for over a year. Now it is obsolete.
1. Address numerous xref issues around the term node and prevent some from occurring for the term children.
2. Embrace Attr as a node even more.
3. Rely on Web IDL's implements and interface primitives to reduce the opportunities for confusion.

Fixes whatwg#597, fixes whatwg#636, fixes whatwg#719, and fixes whatwg#770.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.