onInit()

Subscribe to init emissions of the Dashlet handle. While init resolves once, onInit is a stream: it also fires on rich-client re-initialization, and it replays the settled init to subscribers that register late.

1. Signature

onInit(listener: (ctx: InitContext, info: InitInfo) => void): () => void;
  • listener — receives the normalized InitContext and an InitInfo metadata object.

  • Returns an unsubscribe function: call it to remove the listener.

2. The four InitSource values

info.source tells you how the emission was produced:

InitSource Meaning

webclientEvent

The first accepted onInit message on the postMessage wire.

richClientSelfInit

The bridge read after window.osClient appeared — self-initialization, no host event.

richClientCallback

A host call of the installed osDashletInit global (first host call, or a later re-initialization).

standalone

The detection cap elapsed without bridge or event; the promise and the listener both observe the degraded state.

3. Semantics

  • Fires on settle. The first settlement delivers the context to all onInit listeners with the matching source.

  • Replay for late subscribers. If the init has already settled (for example a framework registers its listener only after mount), the listener fires immediately with the settled context and its original source — late registration never misses the init.

  • Rich-client re-emission. In the rich client the init can re-emit: a first osDashletInit callback arriving after an earlier self-initialization (or a callback beating the detection poll tick) delivers a fresh context with source: 'richClientCallback'. Subsequent callbacks route to onUpdate instead.

  • Listener errors. An exception thrown by an onInit listener (normal or replay delivery) is routed to onError listeners — it never breaks the host call or the other listeners.

4. Examples

const off = dashlet.onInit((ctx, info) => {
    console.log(info.source, ctx.environment);
    render(ctx);
});

// later
off(); // unsubscribe