Skip to content

ModelEventArgs

type ModelEventArgs = object;

Map from event name to payload shape, indexing the events that Model.on can subscribe to. Each entry below documents the trigger and payload semantics for one event.

model.on('error', ({ workbookName, error }) => {
console.warn(`Error in ${workbookName}: ${error.message}`);
});
model.on('recalc', m => console.log('recalc finished', m.id));
addsheet: object;

A sheet was added to one of the model’s workbooks. Re-emitted from the underlying Workbook; subscribing on the model auto-installs the forwarder on every workbook in the model, including those attached after subscription.

index: number;
sheetName: string;
workbookName: string;

attach: object;

A workbook was attached to the model (Model.addWorkbook / Model.attachWorkbook).

workbookName: string;

beforerecalc: Model;

Emitted at the start of Model.recalculate, before any cell is recalculated. Payload is the model.


detach: object;

A workbook was detached from the model (Model.removeWorkbook).

workbookName: string;

error: object;

A ModelError was raised during a model operation. seenBefore is true when the same error fingerprint has been emitted previously in this model’s lifetime, so consumers can deduplicate repeated errors.

error: ModelError;
seenBefore: boolean;
type: string;
workbookId: string | undefined;
workbookName: string | undefined;

metrics: MetricsEvent;

Function-call timing sample (one event per evaluated function or operator) emitted by a workbook during cell evaluation. The model re-emits a workbook’s metrics events when there are listeners on the model; the wiring is installed on every workbook in the model, including those attached after subscription.


native-update: object;

External workbook update from the host environment (e.g. GRID native), announcing that the named workbook should be considered modified at lastWrite. Apiary itself does not emit this event; it is forwarded by the host so consumers can invalidate caches.

action: string;
lastWrite: number;
workbookId: string | undefined;
workbookName: string | undefined;

recalc: Model;

Emitted at the end of Model.recalculate. Payload is the model.


recalcEvent: RecalcEvent;

Per-cell recalculation event emitted during Model.recalculate (one event per recalculated cell, plus phase markers). Subscribe to trace recalculation; see RecalcEvent for the full payload shape.


reset: object;

Model state was cleared via Model.reset.