Function: useOnCommand()
ts
function useOnCommand<R, P, T>(host: ReactiveElement, options: UseOnCommandOptions<R, P, T>): OnCommandController<R, P, T>;Defined in: src/wirestate-lit/commands/use-on-command.ts:48
Registers a command handler for the host element's lifetime.
Type Parameters
| Type Parameter | Default type |
|---|---|
R | unknown |
P | unknown |
T extends CommandType | CommandType |
Parameters
| Parameter | Type | Description |
|---|---|---|
host | ReactiveElement | Host element. |
options | UseOnCommandOptions<R, P, T> | Command handling options. |
Returns
OnCommandController<R, P, T>
The command controller instance.
Remarks
Registers when the host connects, unregisters when it disconnects, and re-registers when the nearest container context changes. Command handlers are stack-based on the active command bus.
Example
typescript
class MyElement extends LitElement {
private onSave = useOnCommand(this, {
type: "SAVE",
handler: (payload) => console.log("Saving:", payload),
});
}