Eventually a module has to be destroyed. To do this you simply call mymodule.destroy()
. This does more than just run your module's defined destroy
logic. When destroy is called on a module it recursively calls .destroy()
on any descendant modules (from the bottom up).
Destroy does the following:
- It runs
.teardown()
to undo any setup logic. - It removes the module from any module it may be nested inside.
- It removes the module from the DOM.
- It unmounts the module from element.
- It runs your module's custom destroy logic.
- It fires a
destroy
event hook. - It sets
module.destroyed
totrue
(useful for checking for destroyed views). - It calls
module.off()
to unbind all event listeners.
NOTE: Once a module module has been destroyed, it cannot be brought back to life. Like initialize
, destroy
can only happen once in the lifetime of a module module.
You may just want to remove a module from it's current context and drop it somewhere else, without actually destroying it. In this case you will want to use .remove()
.
Remove will:
- Remove a module from from any module it may be nested inside.
- Remove the module's element (
.el
) from the DOM (if applicable), unless the called with{ fromDOM: false }
.