Skip to content

Component

Official

A component that can be loaded and unloaded.

Import:

import { Component } from 'obsidian';

Signature:

export class Component

Constructor

new Component()

Constructor.

To extract the constructor type, use ExtractConstructor<Component>.

Properties

PropertyTypeDescription
_childrenComponent[]Child Components attached to current component, will be unloaded on unloading parent component.
_eventsEventRef[]Events that are attached to the current component, will be detached on unloading parent component.
_loadedbooleanWhether the component and its children are loaded.

Methods

MethodReturnsDescription
addChild(component)TAdds a child component, loading it if this component is loaded.
load()voidLoad this component and its children.
onload()voidOverride this to load your component.
onunload()voidOverride this to unload your component
register(cb)voidRegisters a callback to be called when unloading.
registerDomEvent(el, type, callback, options?)voidRegisters a DOM event to be detached when unloading.
registerDomEvent(el, type, callback, options?)voidRegisters a DOM event to be detached when unloading
registerDomEvent(el, type, callback, options?)voidRegisters a DOM event to be detached when unloading
registerEvent(eventRef)voidRegisters an event to be detached when unloading.
registerInterval(id)numberRegisters an interval (from setInterval) to be cancelled when unloading. Use window.setInterval instead of setInterval to avoid TypeScript confusing between NodeJS vs Browser API
registerScopeEvent(keymapEventHandler)voidRegister a scope keymap event handler to be removed on unload.
removeChild(component)TRemoves a child component, unloading it.
unload()voidOverride this to unload your component.

Links to this page: