canjs / can-component

Custom elements and widgets
https://canjs.com/doc/can-component.html
MIT License
8 stars 8 forks source link

Instantiated components should not be bound #278

Closed justinbmeyer closed 5 years ago

justinbmeyer commented 6 years ago

If we do something like:

new ChildComponent({
  viewModel: {
    prop: value.from(this, "parentProp");
  }
});

This will create a memory leak because the ChildComponent will be listening on the parent component's parentProp.

I propose that components only "activate" once they are in the DOM. For testing, I suggest we add a .connect() and .disconnect() method that will "activate" and call the viewModel.connectedCallback() method.

I think this might be a breaking change, though I would bet $$$$ that I'm the only one using this feature currently.

justinbmeyer commented 6 years ago

For 5.0, I think we should create the .disconnect() method so folks can at least teardown manually if they need to.

justinbmeyer commented 5 years ago
new ChildComponent({
  initializeBindings: false,
  viewModel: {
    prop: value.from(this, "parentProp");
  }
});