Перейти к содержимому
GitHubXDiscord

getDefaultRuntime

Стабильный · с 0.1.0

Возвращает глобальный Runtime по умолчанию, лениво создавая его при первом вызове. К этому рантайму обращаются все биндинги, когда в дереве нет <TriggerRuntimeProvider>. Большинство приложений никогда не зовут его напрямую — это деталь реализации хуков.

Функция идемпотентна. Первый вызов конструирует рантайм с опциями по умолчанию; каждый последующий вызов возвращает тот же экземпляр, пока setDefaultRuntime его не заменит.

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

Нет.

Один общий экземпляр Runtime. Последующие вызовы возвращают ту же ссылку (===).

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