When is shadowRoot available to a polymer component?

前端 未结 2 842
南方客
南方客 2021-01-14 10:19

I\'m having trouble understanding when access to the shadowRoot of a component is available. Here is an image of a set of nested components:

相关标签:
2条回答
  • 2021-01-14 10:56

    I find your description difficult to understand but usually in attached after the super.attached(); call all things are proper initialized.

    If you can provide the minimal code that allows to reproduce your problem it would be easier to make concrete suggestions.

    In core-elements (JavaScripts) ready() callback is used most of the time instead of attached. I haven't investigated which one is called earlier/later because attached (was enteredView) never failed me.

    0 讨论(0)
  • 2021-01-14 11:14

    Typically, if you're extending PolymerElement the order of the main callbacks will be ready, created, attached. These happen top-down: they're called on ancestors before descendants. It might confusing that ready is called first, but it's because PolymerElement.created calls it after setting up the DOM and even handlers, and because of constructor ordering that happens before your classes created constructor.

    Polymer also adds a domReady method that you can override which is called when your element's children are guaranteed to have been created. That might be what you need.

    See http://www.polymer-project.org/docs/polymer/polymer.html#lifecyclemethods for details on the lifecycle methods.

    First I would see if you can sidestep the ordering issue with data-binding and declarative events, though.

    0 讨论(0)
提交回复
热议问题