Skip to content

onSource

Hears what the event sources say: loading, a fetch that failed, events refused, saves.

Type(n: SourceNotice) => void
Defaultnot set
Live update (update())No — at creation only
Declared inpackages/core/src/kernel.ts

It receives one notice at a time, by type:

  • loading ({ loading }): true while anything is fetched — a spinner.
  • error ({ sourceId, error }): a fetch failed for good, after its retries; what was shown stays.
  • problems ({ sourceId, report }): events of a delivery were refused or bent (report.problems, each { code, severity, path, detail }). The events option’s own come here too when they load late (above 2 000 events).
  • save-error ({ sourceId, edits, error, reverted }) and saved: a source’s save refused (reverted: the edits put back; or, when the events changed again meanwhile, the source fetched again) or done.

It is read when the calendar is made. A source’s bad data never throws: it comes here (a small events array’s problems are in calendar.kernel.getProblems() instead).

import { jsonSource } from '@dzcalendar/core';
import { createCalendar } from '@dzcalendar/dom';
const spinner = document.getElementById('spinner')!;
createCalendar(element, {
timeZone: 'Europe/Paris',
sources: [jsonSource('appointments', { url: '/api/rendez-vous', retry: { attempts: 2, backoffMs: 500 } })],
onSource: (notice) => {
if (notice.type === 'loading') spinner.hidden = !notice.loading;
if (notice.type === 'error') console.error(`${notice.sourceId} could not be fetched`, notice.error);
if (notice.type === 'problems') console.warn(notice.report.problems);
},
});

In the frameworks it is an output: Angular’s (sourceNotice), React’s onSourceNotice, Vue’s @source-notice. Their controllers also keep loading and problems to read.