createRuntime
createRuntime returns an isolated Runtime — the container that holds triggers, conditions and actions for a tree of components. Most apps create one runtime in main.tsx and pass it down via <TriggerRuntimeProvider>. Skip the call entirely and Triggery uses a lazily created default runtime via getDefaultRuntime.
Import
Section titled “Import”Signature
Section titled “Signature”Options
Section titled “Options”| Field | Type | Default | Description |
|---|---|---|---|
inspector | boolean | { dev?: boolean; prod?: boolean } | InspectorFactory | DEV true, PROD false | Enable / disable the per-run inspector. v0.10+: pass createInspectorFactory() from @triggery/core/inspect for the bundle-friendly opt-in pattern. |
inspectorBufferSize | number | 50 | Inspector ring-buffer size. Ignored when the inspector is disabled. |
middleware | readonly Middleware[] | [] | Middleware chain. |
maxCascadeDepth | number | 3 | Maximum cascade depth — action → fireEvent → …. Runs above this are skipped with 'overflow'. |
See RuntimeOptions for the full shape.
Returns
Section titled “Returns”A Runtime object. The methods most apps touch:
| Method | Description |
|---|---|
runtime.fire(event, payload) | Dispatch an event through the scheduler. Returns void. |
runtime.fireSync(event, payload) | Dispatch synchronously (bypass scheduler). For tests and bench. |
runtime.subscribe(listener) | Listen for every recorded run. Returns a RegistrationToken. |
runtime.getInspectorBuffer() | Most-recent N inspector snapshots. |
runtime.getTrigger(id) | Look up a registered trigger. |
runtime.graph() | JSON-friendly snapshot of the registry — used by triggery graph CLI. |
runtime.dispose() | Abort all in-flight runs and drop all registrations. |
register* methods (registerTrigger, registerCondition, registerAction) are also part of the surface, but bindings handle them for you. v0.10+ adds runtime.subscribeAction(triggerId, name, cb, options?) — the additive subscription path that powers trigger.action(name).subscribe(cb) and is what the framework useAction hooks now use under the hood. Every subscriber runs on each emit, alongside any handler registered through registerAction.
Examples
Section titled “Examples”Default — one runtime at the root
Section titled “Default — one runtime at the root”Isolated runtime per test
Section titled “Isolated runtime per test”Tight cascade limit
Section titled “Tight cascade limit”With middleware
Section titled “With middleware”Inspector explicitly disabled
Section titled “Inspector explicitly disabled”Or per-environment: