Maksim  Savitskiy Maksim Savitskiy - 7 months ago 32
Javascript Question

Unregister Material Disign Lite component in Backbone view

I'm using MDL with Backbone.
How can i unregister components before removing view that contains any MDL component.

To register components i'm using

componentsHandler.upgradeDOM()
function from MDL. But without
componentsHandler.unregisterComponents()
appears memory leak.

I can't get MDL components that associated with current view to unregister them =(

Answer

I found solution of this problem. I just add this code in remove method of all my Backbone views:

var components = this.el.querySelectorAll('[data-upgraded]'); 
if (components.length > 0) {
componentHandler.downgradeElements(components);
} 

This code find all upgraded elements in view and downgrade them.