garris / TremulaJS

TremulaJS: Picture Streams + Momentum Engine + Bézier Paths + Multi-Device
GNU General Public License v3.0
1.31k stars 82 forks source link

How to unload tremula #18

Closed garris closed 9 years ago

garris commented 9 years ago

Someone recently asked how to unload tremula -- IOW is there a tremula.destroy() method?

garris commented 9 years ago

The short answer is, not in one method. But it is pretty simple to do manually.

Assuming you are starting with something like this...

$tremulaContainer = $('.tremulaContainer');
var tremula = new Tremula();
var config = tremulaConfigs.default.call(tremula);
tremula.init($tremulaContainer,config,this);

You can then do this...

tremula.Grid.removeAll(); //removes all DOM bindings and references
tremula = null; //removes reference to the tremula object
$tremulaContainer.remove(); //removes parent DOM and any associated listeners.

tremula.Grid.removeAll(); does most of the work. I should double check if Hammer.js requires anything special -- I think the remove() method should do it though. If I find anything else I will note it here.