Skip to main content

intercept

Registers a handler that runs before regular handlers for a given action. Returning false (or a promise resolving to false) cancels the action.

Usage

intercept<A extends keyof StoreActions>(
action: A,
handler: (data: StoreActions[A]) => void | boolean | Promise<boolean>,
config?: IEventConfig
): void;

interface IEventConfig {
tag?: string | number | symbol;
}
ParameterTypeDescription
actionkeyof StoreActionsAction name (e.g. "add-event", "delete-event", "navigate-to").
handler(data) => void | boolean | Promise<boolean>Receives the payload. Return false to cancel; anything else lets it proceed.
configIEventConfigOptional. Pass tag to identify the interceptor for later detach.

Example

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

let api = $state<CalendarInstanceApi>();

function init(a: CalendarInstanceApi) {
api = a;
api.intercept("delete-event", ({ id }) => {
return confirm(`Delete event ${id}?`);
});
}
</script>

<Calendar events={[]} {init} />
  • on — observe actions instead of cancelling them.
  • detach — remove a registered interceptor by tag.
  • exec — actions that flow through the interceptor chain.
  • Actions overview — payload shape per action.