Edit this page

up.script up.destructor(element, destructor)
JavaScript function

Registers a function to be called when the given element is destroyed.

Elements are destroyed when they are swapped during render pass, when their layer closes, or when up.destroy() is called on the element or its container.

An alternative way to register a destructor function is to return it from your compiler function.

Example

The code below will log a message when element exits the DOM:

let element = document.querySelector('.element')
up.destructor(element, () => console.log('Element was destroyed!'))

Reusing destructor functions

You may reuse the same destructor function for multiple element. The destructor function is called with the element being destroyed:

let fn = (element) => console.log('Element %o was destroyed', element)

for (let element of document.querySelector('div')) {
  up.destructor(fn)
}

Parameters

element Element

The element to observe.

destructor Function(Element)orArray<Function(Element)>

One or more destructor functions.