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

Allow omission of attributes if attributeOldValue or attributeFilter is present #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thompsongl
Copy link

Per the whatwg standard, attributes has no default value in MutationObserverInit (i.e., not false).
Also, attributes should be set to true if implicitly true (i.e., attributeOldValue or attributeFilter is specified).

The observe(target, options) method, when invoked, must run these steps:

  1. If either options’s attributeOldValue or attributeFilter is present and options’s attributes is omitted, then set options’s attributes to true.

This PR will allow the omission of the attributes option if attributeOldValue or attributeFilter is specified.


Depending on your setup, you can work around this in the meantime by patching the observe method:

const MutationObserver = require('mutation-observer');
const _observe = MutationObserver.prototype.observe;
MutationObserver.prototype.observe = function observe(target, options) {
  const needsAttributes = options.hasOwnProperty('attributeOldValue') || options.hasOwnProperty('attributeFilter');
  if (needsAttributes && !options.hasOwnProperty('attributes')) {
    options.attributes = true;
  }
  Function.prototype.call(_observe, this, target, options);
};
Object.defineProperty(window, 'MutationObserver', { value: MutationObserver });

(h/t @chandlerprall)

@thompsongl
Copy link
Author

Circling back to this to say that the above is only valid if IE11 support is not of concern.

The polyfill appears to implement an old(?) version of the spec in which attributes is required in the case described. It's likely better to handle the difference per project than to alter the polyfill.

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.

None yet

1 participant