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

Databinding breaks after removing and reattaching an element to the DOM #311

Closed
ratatatata opened this issue Oct 9, 2013 · 3 comments
Closed

Comments

@ratatatata
Copy link

Hi,

in the most recent version from git (date 2013-09-10), databinding seems to break if one removes an element from the DOM and reattaches it afterwards.

Tested in current versions of all evergreen browsers (especially chrome 30.0.1599.69 m).

Following fiddle demonstrates the problem: http://jsfiddle.net/Ysasn/1/

It contains a button that switches between two instances of an element that contains some basic databinding (the elements simply mirror the input of a textbox to a span; each button click removes the previously displayed instance from the DOM and (re)attaches the other instance of this databinding-test-element).
The databinding works fine for the first two clicks, when the my-binding-test elements get attached to the DOM the first time. BUT, after having clicked a third time (when the first my-binding-test instance gets reattached to the DOM) the data-binding is broken and doesn't propagate any changes anymore. Of course, this demo works fine, when reinstantiating the my-binding-test elements on each button click.

Don't hestitate to ask if you need any further information.

Regards,
André

@frankiefu
Copy link
Member

Bindings are removed asynchronously when the element is removed from the document. To avoid that, call cancelUnbindAll() immediately after the element is removed.

http://www.polymer-project.org/polymer.html#bindings

@sorvell
Copy link
Contributor

sorvell commented Oct 9, 2013

As Frankie noted, the intention is that you call cancelUnbindAll after removing sub1 or sub2. However, you'll currently need to also call CustomElements.takeRecords to ensure that the sub's leftViewCallback is processed first. Here's a working version:

http://jsfiddle.net/d5dED/2/

I've made another issue, linked above, to avoid the need to write polyfill aware code.

@sorvell
Copy link
Contributor

sorvell commented Oct 15, 2013

I'd like to point out that using conditional templates makes this type of construction very simple. Here's an example:

http://jsfiddle.net/FbkvY/2/.

Also see #312. The new preventDispose property can be used for this type of construction. Here's an updated fiddle: http://jsfiddle.net/WJ36P/1/.

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