Skip to content

attributeChanged is not called under some circumstances #438

Description

@gaplyk

When Element created dynamically and appended to the dom:

var el = new PolymerSampleElement();
document.body.appendChild(el);

method attributeChanged called.

then you remove this element from the dom:
document.body.removeChild(el);

when you try to add, already created, element back to the dom method attributeChanged is not called.

Activity

  1. gaplyk commented on Mar 6, 2014

    @gaplyk
    Author

    example is a little bit complicated than i describe.ill try to reproduce this in a simple way (i'm not able to publish part of the project).

  2. gaplyk commented on Mar 6, 2014

    @gaplyk
    Author

    Example:
    http://jsbin.com/buqeturu/1/edit

    but i could find polymer-flex-layout.html in CDN.

    Steps to reproduce: click "show 1", "show 2", "show 1".

    after last click method layoutContainerChanged inside polymer-flex-layout is not called for component inside polymer-test1

  3. dfreedm commented on Mar 7, 2014

    @dfreedm
    Member

    The binding mechanism that controls things like layoutContainerChanged is unbound asynchronously after the element is detached. If in detached, you call this.cancelUnbindAll, the layoutContainerChanged bindings will survive after being detached, and work again when re-attached.

    <polymer-flex-layout> does not call this method in detached, and that's a bug.

    Thanks for reporting this!

  4. dfreedm commented on Mar 7, 2014

    @dfreedm
    Member

    After discussing this with @frankiefu and @sorvell, I remember why <polymer-flex-layout> does not keep its bindings: we can't determine if you will add the element back, or let it be garbage collected.

    Because MDV must keep references to the element to process data binding, we have to dispose of the data bindings on removal from the DOM, or there will be a memory leak.

    Therefore, you have to be the one to call cancelUnbindAll in your application if you hold on to an element after you have removed it from the DOM and need the bindings to work.

    Whenever javascript gains a Weak Reference, or MDV becomes native, then we can remove this restriction.

    @ebidel This seems like an important topic to cover in the databinding docs (probably in big text).

  5. ebidel commented on Mar 7, 2014

    @ebidel
    Contributor

    We have extensive docs on "life of a binding" here:
    http://www.polymer-project.org/docs/polymer/polymer.html#bindings

    This will probably find its way into the data-binding docs after they're revamped.

  6. dfreedm commented on Mar 7, 2014

    @dfreedm
    Member

    @ebidel Ah good! I was expecting to find it in the Data Binding section, maybe there should be a link there as well?

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions