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;
}
| Parameter | Type | Description |
|---|---|---|
action | keyof StoreActions | Action 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. |
config | IEventConfig | Optional. Pass tag to identify the interceptor for later detach. |
Example
<script setup lang="ts">
import { Calendar } from "@svar-ui/vue-calendar";
import type { CalendarInstanceApi } from "@svar-ui/vue-calendar";
const api = ref<CalendarInstanceApi>();
function init(a: CalendarInstanceApi) {
api.value = a;
api.value.intercept("delete-event", ({ id }) => {
return confirm(`Delete event ${id}?`);
});
}
</script>
<template>
<Calendar :events="[]" :init="init" />
</template>
Related articles
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.