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

[0.8] getDistributedNodes() does not update when distributed content changes #1449

Closed
atotic opened this issue Apr 24, 2015 · 4 comments
Closed

Comments

@atotic
Copy link
Contributor

atotic commented Apr 24, 2015

_distributedNodes array does not get updated when underlying nodes are added/removed.

If you start off with:

    <dom-module id="bug-distributor">
      <template>
        <content id="pcontent" select="p"></content>
      </template>
    </dom-module>

    <bug-distributor>
      <p>Paragraph 1</p>
      <p>Paragraph 2</p>
      <p>Paragraph 3</p>
    </bug-distributor>

bug-distributor.getDistributedNodes().length is 3.

Then you remove all the distributed nodes:

document.querySelectorAll('p').forEach( p.remove())

bug-distributor.getDistributedNodes().length is 3, should be 0.

Is there a workaround, call one can make to update the list of distributedNodes?

@arthurevans
Copy link

I think you should be using Polymer.dom to remove the nodes.

@atotic
Copy link
Contributor Author

atotic commented Apr 24, 2015

I've tried using Polymer.dom, same result.

    var allPs = document.querySelectorAll('p');
    Array.prototype.forEach.call( allPs, function(p) {
      Polymer.dom((Polymer.dom(p).parentNode)).removeChild(p);
    });

@arthurevans
Copy link

Ah, sorry. I see what's wrong. These operations may be async, so you need to call flush() after removing the children.

Call Polymer.dom.flush() before calling getDistributedNodes the second time:

http://jsbin.com/rusoro/4/edit?html,console,output

I think this was just shorthand in your description, but I believe that getDistributedNodes needs to be called on the content node, not the host element.

On async operations: see the note here:

https://www.polymer-project.org/0.8/docs/devguide/local-dom.html#dom-api

These notes are a little hard to read. I'll try and figure out a way to make this more prominent.

@atotic
Copy link
Contributor Author

atotic commented Apr 24, 2015

Thanks for helping out with this. Still not quite up to speed with Polymer dom.

@atotic atotic closed this as completed Apr 24, 2015
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

2 participants