Skip to main content

on

Registers a handler for a store action. The handler runs after interceptors, alongside the built-in handler, and receives the action payload.

Usage

on<A extends keyof StoreActions>(
name: A,
handler: (data: StoreActions[A]) => void | boolean | Promise<boolean>,
config?: IEventConfig
): void;
ParameterTypeDescription
namekeyof StoreActionsAction id ("add-event", "update-event", "navigate-to", ...).
handler(data) => void | boolean | Promise<boolean>Called with the action payload. Return value is ignored on on.
configIEventConfigOptional bus config (tag, once); use tag to detach later.

Use intercept instead of on when you need to block or modify an action before it runs.

Example

<script lang="ts">
import { Calendar } from "@svar-ui/svelte-calendar";
import type { CalendarInstanceApi } from "@svar-ui/svelte-calendar";

let api: CalendarInstanceApi;

function init(a: CalendarInstanceApi) {
api = a;
api.on("add-event", p => {
console.log("event added:", p.event);
});
}
</script>

<Calendar {init} events={[]} date={new Date()} />
  • intercept — block or confirm before the action runs.
  • detach — remove a registered handler by tag.
  • exec — programmatic equivalent of user actions.
  • Actions overview — payload shapes for each action.