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

attributeChangedCallback may be expensive for some attributes #350

Closed
dominiccooney opened this issue Nov 17, 2015 · 4 comments
Closed

attributeChangedCallback may be expensive for some attributes #350

dominiccooney opened this issue Nov 17, 2015 · 4 comments

Comments

@dominiccooney
Copy link
Contributor

Implementer feedback: In Blink, the "style" attribute is serialized lazily so that a code block like:

 elem.style.color = 'red';
 elem.style.textDecoration = 'underline';
 elem.style.fontWeight = 'bold';

only generates one serialization of the properties. This is because realizing the string could be expensive. With Custom Elements, you would reasonably expect this to generate three attributeChangedCallback invocations with three serializations of the string.

There are a lot of design alternatives that would avoid this, with various trade-offs. For example, the UA could be permitted to dispatch those callbacks later and coalesce them; the API could let authors specify specific attributes to watch; the attributeChangedCallback could be supplied with only the attribute name and make the author responsible to poll the attribute; etc. (Some of these options have been discussed in the past in other contexts.)

@domenic
Copy link
Collaborator

domenic commented Nov 17, 2015

Gut reaction: I like both the "supply only the attribute name" and "supply a list of attributes to watch" ideas.

@annevk
Copy link
Collaborator

annevk commented Nov 17, 2015

This is why mutation observers have several configuration options for attributes: https://dom.spec.whatwg.org/#dictdef-mutationobserverinit. attributeFilter and attributeOldValue. We should probably copy that in some way.

@WebReflection
Copy link

only generates one serialization of the properties

if the purpose is to be able to understand old and new value, why wouldn't that be notified only once, after such serialization happens?

I personally think it would be way more useful to receive one style changed notification instead of N times per each single change, for the very same reason it's useful in Blink ( less operations per time, snappier, happy UI and developers )

... or ... is the problem that each of those should trigger different event? what would be the attribute name then, if not just style ?

@hayatoito
Copy link
Contributor

Let's merge this issue to #367

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants