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

attributeChanged is not called under some circumstances #438

Closed
gaplyk opened this issue Mar 6, 2014 · 6 comments
Closed

attributeChanged is not called under some circumstances #438

gaplyk opened this issue Mar 6, 2014 · 6 comments
Assignees

Comments

@gaplyk
Copy link

gaplyk commented Mar 6, 2014

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.

@gaplyk
Copy link
Author

gaplyk commented Mar 6, 2014

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).

@gaplyk
Copy link
Author

gaplyk commented Mar 6, 2014

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

@dfreedm
Copy link
Member

dfreedm commented Mar 7, 2014

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!

@dfreedm
Copy link
Member

dfreedm commented Mar 7, 2014

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).

@dfreedm dfreedm closed this as completed Mar 7, 2014
@ebidel
Copy link
Contributor

ebidel commented Mar 7, 2014

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.

@dfreedm
Copy link
Member

dfreedm commented Mar 7, 2014

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants