Skip to main content

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;
};
FieldTypeDescription
getState() => StateReturns a snapshot of the current store state.
getReactiveState() => ReactiveStateReturns 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 | undefinedReturns one event by id.
exec(action, payload) => anyDispatches a store action through interceptors and handlers.
setNext(handler) => anyAppends a handler at the end of the event-bus chain (used for providers).
intercept(action, handler, config?) => voidRegisters a handler that runs before regular ones; returning false cancels.
on(action, handler, config?) => voidRegisters a handler invoked after regular ones run.
detach(tag) => voidRemoves 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} />