init
One-shot callback fired after the calendar store finishes initializing. Receives the same instance API as bind:this. Use it to store a reference for programmatic control or to attach a data provider.
Usage
init?: (api: CalendarInstanceApi) => void;
type CalendarInstanceApi = {
getState: () => State;
getReactiveState: () => ReactiveState;
getStores: () => { data: CalendarStore };
getEvents: (start?: Date, end?: Date) => CalendarEvent[];
getEvent: (id: string | number) => CalendarEvent | undefined;
exec: (action, payload) => any;
setNext: (handler: any) => any;
intercept: (action, handler, config?) => void;
on: (action, handler, config?) => void;
detach: (tag: string) => void;
};
| Field | Type | Description |
|---|---|---|
getState | () => State | Returns a snapshot of the current store state. |
getReactiveState | () => ReactiveState | Returns reactive stores for each state field. |
getStores | () => { data: CalendarStore } | Returns the underlying store instance. |
getEvents | (start?, end?) => CalendarEvent[] | Returns events, optionally filtered by date range. |
getEvent | (id) => CalendarEvent | undefined | Returns one event by id. |
exec | (action, payload) => any | Dispatches a store action through interceptors and handlers. |
setNext | (handler) => any | Appends a handler at the end of the event-bus chain (used for providers). |
intercept | (action, handler, config?) => void | Registers a handler that runs before regular ones; returning false cancels. |
on | (action, handler, config?) => void | Registers a handler invoked after regular ones run. |
detach | (tag) => void | Removes a previously registered handler or interceptor by tag. |
Fires once. Subsequent re-renders do not call init again.
Example
<script>
import { Calendar, RestDataProvider } from "@svar-ui/svelte-calendar";
const provider = new RestDataProvider("/api");
function init(api) {
api.setNext(provider);
}
</script>
<Calendar events={[]} {init} />
Related articles
exec— dispatch actions through the captured api.setNext— wire aRestDataProvideronceinitfires.intercept— block or confirm actions before they run.- Methods overview — full surface of the instance API.
- Backend integration — typical
inituse case.