chiasm-project / chiasm

A browser based environment for interactive data visualizations.
MIT License
184 stars 27 forks source link

Cannot remove window resize event listener in the layout plugin #36

Closed Hypercubed closed 9 years ago

Hypercubed commented 9 years ago

After the element is removed and the model is no longer referenced the window resize event listener in the layout plugin (here https://github.com/curran/chiasm/blob/gh-pages/src/plugins/layout/layout.js#L35) remains. We can add the following to the layout plugin:

    model.destroy = function(){
      window.removeEventListener("resize", setBox);
    };

But I think the plugins destroy methods still need to be called manually using something like:

    chiasm.getComponent('layout').then(function(comp) {
        comp.destroy();
    });
curran commented 9 years ago

Great catch. Yes, there is a listener leak here. I think your first suggestion looks good. The destroy function will get invoked if the layout is removed from the Chiasm configuration. So, in the case you are wanting to tear down the whole Chiasm runtime, you can set the config object to {}, which should cause the destroy function to be invoked on all components present (including layout).

Thank you for finding this.