Fields
addListener
Registers a listener that is invoked when the trigger fires.
This function has two signatures:
addListener(callback)— Simple form, just pass the callback function.addListener(anchor, callback)— Pass an anchor object and a callback. The anchor is stored alongside the listener and passed to the callback when invoked. This is useful for preventing garbage collection of objects you need to keep alive while the listener is active.
local vm = context:viewModel()) and add listeners without storing
the ViewModel elsewhere, it may be garbage collected after the function
returns. To prevent this, either:
- Store the ViewModel on
self(e.g.,self.vm = context:viewModel()) - Pass the ViewModel as the anchor parameter to
addListener
removeListener
Removes a previously registered listener.
Always remove listeners when they are no longer needed to avoid leaks.
This function has two signatures:
removeListener(callback)— Pass the callback function to remove.removeListener(anchor, callback)— Pass an anchor and the callback. The anchor parameter is accepted for API symmetry withaddListener, but only the callback is used for matching.