CommandHandlerComponent.registerCommandHandlers method
CommandHandlerComponent › registerCommandHandlers
Builds the command handlers and registers them with Obsidian, giving each its own runtime registration context. Each handler's command is added immediately; the returned DisposableEx removes the commands registered by this call — and any menu events those handlers registered via their context's MenuEventRegistrar — when disposed. Any command still registered when the component unloads is removed automatically.The factory is invoked once more for every additional menu surface, so a plugin declares its handlers ONCE and all surfaces are fed. Those extra passes add no commands — the palette already has every command from the first pass.
Which component's unload removes them is the caller's to choose:
options.lifetimeOwner for this one batch, otherwise whatever this component's CommandLifetimeOwnerProvider resolves to, which defaults to the component itself. A command must never outlive the collaborators its handler closes over — left on a longer-lived owner it stays in the palette calling into torn-down objects — so the owner to name is the shortest-lived thing the batch depends on.Signature:
registerCommandHandlers(commandHandlerFactory: CommandHandlerFactory, options?: CommandHandlerComponentRegisterCommandHandlersOptions | undefined): Promise<DisposableEx>Parameters:
| Parameter | Type | Description |
|---|---|---|
| commandHandlerFactory | CommandHandlerFactory | Builds a fresh set of command handlers, once per menu surface. |
| options? | CommandHandlerComponentRegisterCommandHandlersOptions | undefined | The registration options. |
Returns: Promise<DisposableEx> — A DisposableEx that unregisters the handlers (commands + menu events) registered by this call.