Skip to content
GitHubXDiscord

getDefaultRuntime

Stable · since 0.1.0

Returns the global default Runtime, creating it lazily on first call. This is the runtime every binding falls back to when no <TriggerRuntimeProvider> is in scope. Most apps never call it directly — it’s an implementation detail of the hooks.

The function is idempotent. The first call constructs a runtime with default options; every subsequent call returns the same instance until setDefaultRuntime replaces it.

import { getDefaultRuntime } from '@triggery/core';
function getDefaultRuntime(): Runtime;

None.

The single shared Runtime instance. Subsequent calls return the same reference (===).

import { createTriggerfunction createTrigger<S extends TriggerSchema>(config: CreateTriggerConfig<S>, runtime?: Runtime): Trigger<S>
Create a trigger and register it in a runtime (the default runtime if none is passed).
@example```ts const messageTrigger = createTrigger<{ events: { 'new-message': { author: string; text: string } }; conditions: { user: { id: string }; settings: { sound: boolean } }; actions: { showToast: { title: string }; playSound: void }; }>({ id: 'message-received', events: ['new-message'], required: ['user', 'settings'], handler({ event, conditions, actions, check }) { if (!conditions.user || !conditions.settings) return; // V1: manual narrowing if (check.is('settings', (s) => s.sound)) actions.playSound?.(); actions.showToast?.({ title: event.payload.author }); }, }); ```
, getDefaultRuntimefunction getDefaultRuntime(): Runtime } from '@triggery/core';
createTrigger
createTrigger<{
    events: {
        ping: number;
    };
}>(config: CreateTriggerConfig<{
    events: {
        ping: number;
    };
}>, runtime?: Runtime): Trigger<{
    events: {
        ping: number;
    };
}>
Create a trigger and register it in a runtime (the default runtime if none is passed).
@example```ts const messageTrigger = createTrigger<{ events: { 'new-message': { author: string; text: string } }; conditions: { user: { id: string }; settings: { sound: boolean } }; actions: { showToast: { title: string }; playSound: void }; }>({ id: 'message-received', events: ['new-message'], required: ['user', 'settings'], handler({ event, conditions, actions, check }) { if (!conditions.user || !conditions.settings) return; // V1: manual narrowing if (check.is('settings', (s) => s.sound)) actions.playSound?.(); actions.showToast?.({ title: event.payload.author }); }, }); ```
<{ events
events: {
    ping: number;
}
: { pingping: number: number } }>({
idid: string: 'demo:ping', eventsevents: readonly "ping"[]: ['ping'], handler
handler: TriggerHandler<{
    events: {
        ping: number;
    };
}, never>
({ event
event: {
    readonly name: "ping";
    readonly payload: number;
}
}) {
consolevar console: Console.logConsole.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
('ping', event
event: {
    readonly name: "ping";
    readonly payload: number;
}
.payloadpayload: number);
}, }); // In a WebSocket adapter, a service worker, or any non-React layer. getDefaultRuntimefunction getDefaultRuntime(): Runtime().firefunction fire(eventName: string, payload?: unknown): void
Fire an event asynchronously (through the scheduler).
('ping', 42);
import { getDefaultRuntimefunction getDefaultRuntime(): Runtime } from '@triggery/core';

export function dumpGraphfunction dumpGraph(): RuntimeGraph() {
  const runtimeconst runtime: Runtime = getDefaultRuntimefunction getDefaultRuntime(): Runtime();
  return runtimeconst runtime: Runtime.graphfunction graph(): RuntimeGraph
JSON-friendly snapshot of the trigger registry — for devtools, the CLI's `triggery graph` command, and tooling that introspects connections.
();
}
import { getDefaultRuntimefunction getDefaultRuntime(): Runtime } from '@triggery/core';

const aconst a: Runtime = getDefaultRuntimefunction getDefaultRuntime(): Runtime();
const bconst b: Runtime = getDefaultRuntimefunction getDefaultRuntime(): Runtime();
consolevar console: Console.logConsole.log(...data: any[]): void
The **`console.log()`** static method outputs a message to the console. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static)
(aconst a: Runtime === bconst b: Runtime); // true — same instance