2

Does the remove child method provided by polymer takes care of cleaning all the dependencies such as event listeners, binded vars, etc. ?

Polymer.dom(parent).removeChild(node)

I want to add/remove many elements programmatically and want to make sure nothing is leaking or nothing is still watching for objects that do not exist anymore.

To add:

  // Create the element
  var paperListbox = document.createElement('paper-listbox');
  paperListbox.setAttribute('depth', depth);
  this.listen(paperListbox, 'iron-select', 'selectionChanged');

  // add it
  Polymer.dom(this.$.container).appendChild(paperListbox);

To remove:

 // get node of interest
 var node0 = Polymer.dom(this.$container).childNodes[0];
 Polymer.dom(this.$.container).removeChild(node0)

Does such a pattern would allow me to add/remove lot of elements properly?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nicolas
  • 2,191
  • 3
  • 29
  • 49
  • You'll probably have to read the source code for `Polymer.dom.removeChild` and do some tests during which you monitor the heap. Probably as long as you delete all the references to the removed nodes the event listeners will be cleaned too (`delete node` after `removeChild`). – Sergiu Paraschiv May 10 '16 at 08:32
  • In the end those elements are actually removed from the DOM tree, aren't they? I'd expect the behaviour to be just the same as with [ordinary DOM manipulation](http://stackoverflow.com/q/12528049/1103498). Is there anything Polymer-specific that you're concerned about? – Tomasz Pluskiewicz May 10 '16 at 11:56
  • Yes they are removed from the tree with a Polymer provided function so my question was, does this Polymer helper takes care of it al for me. For instance does it deletes all the events listeners, etc. – Nicolas May 10 '16 at 12:41

0 Answers0