Coder Social home page Coder Social logo

Comments (5)

WebReflection avatar WebReflection commented on June 8, 2024

the TL;DR answer is: it's a feature, not a bug.

The reason MutationObserver is used is because it's faster and it scales more when you change many things at once. It's the requestAnimationFrame equivalent for attribute changes and I believe even the native implementation works in a similar way behind the scene.

You don't want to change in a blocking/synchronous way attributes because that won't perform any good for bigger projects. Each little attribute change might trigger synchronous behaviors in all subnodes of a custom elements too or vice versa.

It's like changing the window size on resize event, you don't know when that blocking behavior would stop. Having that batched and optimized natively is a great thing.

Now, I understand the createdCallback gotcha and I've provided a work around for that, but I start believing you really have some problem with asunchronous code in general ... or if you could be so kind to explain me why would you want or need that, I might re-consider this answer.

from document-register-element.

WebReflection avatar WebReflection commented on June 8, 2024

P.S. MutationObserver like Object.observe were introduced to exactly avoid synchronous blocking changes, even to regular Objects. If I were you, I rather try to figure out how to deal with these scenarios instead of asking everyone and everything to be sync and blocking. Just saying, those APIs are not there to annoy developers but to actually help them.

from document-register-element.

opinel avatar opinel commented on June 8, 2024

TL;DR: I just want to have a real consistent cross-browser behavior.
If I would override the setAttribute method as you do in one of your examples, I would get this behavior out of the box. The only use-case I would not support would be the manipulation through the web-inspector in the developer's browser.

from document-register-element.

WebReflection avatar WebReflection commented on June 8, 2024

You have a consistent behavior, you define what should happen in the CustomElement prototype and events definition and you got it. That is what this polyfill is about, an API that works across platform consistently and it does ... so that's the good news.

The bad one is, you are apparently doing things that won't even work on Polymer since it uses same MutationObserver behavior because that's what you want to do as well but you don't know it yet ;-)

from document-register-element.

WebReflection avatar WebReflection commented on June 8, 2024

btw, you didn't give me a single valid use case for this request, so I am going to close this. Feel free to change my mind with real needs and please do not mention your testing frameworks, thank you for your understanding.

from document-register-element.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.