Skip to main content

Lifecycle Callbacks

Special methods called lifecycle callbacks allow you to respond whenever a module connects to and disconnects from the document.

import { Module } from '@by-association-only/theme-module'

export default class extends Module {
initialize () {
// …
}

setupListeners () {
// …
}

ready () {
// …
}

destroy () {
// …
}
}

Methods

You may define any of the following methods in your module:

MethodDescription
initialize()When the module is first instantiated. Typically used for module setup
setupListeners()After module initialisation. Should be used to set up any event listeners needed by the module
ready()Once the module has initialised. All of the listeners are already added by this point
destroy()Called before the module is destroyed. Should be used to make sure the module can teardown elegantly.