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
Section titled “Import”import { getDefaultRuntime } from '@triggery/core';
Signature
Section titled “Signature”function getDefaultRuntime(): Runtime;Parameters
Section titled “Parameters”None.
Returns
Section titled “Returns”The single shared Runtime instance. Subsequent calls return the same reference (===).
Examples
Section titled “Examples”Fire an event from outside React
Section titled “Fire an event from outside React”import { createTrigger function 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). , getDefaultRuntime function 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). <{ events events: {
ping: number;
}
: { ping ping: number : number } }>({
id id: string : 'demo:ping',
events events: readonly "ping"[] : ['ping'],
handler handler: TriggerHandler<{
events: {
ping: number;
};
}, never>
({ event event: {
readonly name: "ping";
readonly payload: number;
}
}) {
console var console: Console .log Console.log(...data: any[]): voidThe **`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;
}
.payload payload: number );
},
});
// In a WebSocket adapter, a service worker, or any non-React layer.
getDefaultRuntime function getDefaultRuntime(): Runtime ().fire function fire(eventName: string, payload?: unknown): voidFire an event asynchronously (through the scheduler). ('ping', 42);Inspect the registry from devtools glue
Section titled “Inspect the registry from devtools glue”import { getDefaultRuntime function getDefaultRuntime(): Runtime } from '@triggery/core';
export function dumpGraph function dumpGraph(): RuntimeGraph () {
const runtime const runtime: Runtime = getDefaultRuntime function getDefaultRuntime(): Runtime ();
return runtime const runtime: Runtime .graph function graph(): RuntimeGraphJSON-friendly snapshot of the trigger registry — for devtools, the CLI's
`triggery graph` command, and tooling that introspects connections. ();
}Lazy construction proof
Section titled “Lazy construction proof”import { getDefaultRuntime function getDefaultRuntime(): Runtime } from '@triggery/core';
const a const a: Runtime = getDefaultRuntime function getDefaultRuntime(): Runtime ();
const b const b: Runtime = getDefaultRuntime function getDefaultRuntime(): Runtime ();
console var console: Console .log Console.log(...data: any[]): voidThe **`console.log()`** static method outputs a message to the console.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/console/log_static) (a const a: Runtime === b const b: Runtime ); // true — same instanceRelated
Section titled “Related” setDefaultRuntime Replace the singleton — useful in tests.
createRuntime Create an isolated runtime.
Runtime type Full method surface.
TriggerRuntimeProvider Inject a runtime through context.