createInspector
Stable · since 0.1.0
Constructs the ring-buffer inspector the runtime uses to record snapshots. The runtime calls this for you when you pass inspectorBufferSize to createRuntime; you only need createInspector directly when building custom runtime infrastructure (e.g. a devtools bridge that wants direct access to record / subscribe).
The implementation is allocation-free on the hot path: O(1) record, fixed slot array, wrap-around index. getBuffer() materializes a newest-first array on demand.
Import
Section titled “Import”import { createInspector } from '@triggery/core';
Signature
Section titled “Signature”function createInspector(bufferSize: number): InspectorImpl;Parameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
bufferSize | number | Number of snapshots to keep. Clamped to a minimum of 1. |
Returns
Section titled “Returns”An InspectorImpl object:
| Method | Signature | Description |
|---|---|---|
record(snapshot) | (s: TriggerInspectSnapshot) => void | Push a snapshot. Wraps around the buffer. Notifies subscribers. |
getBuffer() | () => readonly TriggerInspectSnapshot[] | Newest-first array of the last N records. |
getLastForTrigger(id) | (triggerId: string) => Snapshot | undefined | Most recent snapshot per trigger id. |
subscribe(fn) | (fn) => () => void | Listener fired on every record. Returns an unsubscribe. |
clear() | () => void | Empty the buffer and the per-trigger map. |
Examples
Section titled “Examples”Build a custom devtools bridge
Section titled “Build a custom devtools bridge”import { createInspector function createInspector(bufferSize: number): InspectorImplRing-buffer inspector. `record` is O(1) — writes into a fixed-size slot array
with a wrap-around index, no `unshift`/`shift` allocations. `getBuffer`
materializes a newest-first array on demand (rare relative to fires). , type TriggerInspectSnapshot type TriggerInspectSnapshot = {
readonly triggerId: string;
readonly runId: string;
readonly eventName: string;
readonly status: "fired" | "skipped" | "errored" | "aborted";
readonly reason?: string;
readonly durationMs: number;
readonly executedActions: readonly string[];
readonly snapshotKeys: readonly string[];
}
} from '@triggery/core';
const inspector const inspector: InspectorImpl = createInspector function createInspector(bufferSize: number): InspectorImplRing-buffer inspector. `record` is O(1) — writes into a fixed-size slot array
with a wrap-around index, no `unshift`/`shift` allocations. `getBuffer`
materializes a newest-first array on demand (rare relative to fires). (200);
inspector const inspector: InspectorImpl .subscribe function subscribe(listener: (snapshot: TriggerInspectSnapshot) => void): () => void ((snapshot snapshot: TriggerInspectSnapshot : TriggerInspectSnapshot type TriggerInspectSnapshot = {
readonly triggerId: string;
readonly runId: string;
readonly eventName: string;
readonly status: "fired" | "skipped" | "errored" | "aborted";
readonly reason?: string;
readonly durationMs: number;
readonly executedActions: readonly string[];
readonly snapshotKeys: readonly string[];
}
) => {
globalThis module globalThis .postMessage function postMessage(message: any, targetOrigin: string, transfer?: Transferable[]): void (+1 overload)The **`window.postMessage()`** method safely enables cross-origin communication between Window objects; _e.g.,_ between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.
[MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/postMessage) (
{ source source: string : 'triggery-bridge', snapshot snapshot: TriggerInspectSnapshot },
'*',
);
});
// Feed it manually — the example assumes you wired up your own dispatch
// recording. The runtime created via `createRuntime` calls `record` for you.
inspector const inspector: InspectorImpl .record function record(snapshot: TriggerInspectSnapshot): void ({
triggerId triggerId: string : 'demo',
runId runId: string : '1',
eventName eventName: string : 'ping',
status status: "fired" | "skipped" | "errored" | "aborted" : 'fired',
durationMs durationMs: number : 0.2,
executedActions executedActions: readonly string[] : ['log'],
snapshotKeys snapshotKeys: readonly string[] : [],
});Tap into latest-per-trigger
Section titled “Tap into latest-per-trigger”import { createInspector function createInspector(bufferSize: number): InspectorImplRing-buffer inspector. `record` is O(1) — writes into a fixed-size slot array
with a wrap-around index, no `unshift`/`shift` allocations. `getBuffer`
materializes a newest-first array on demand (rare relative to fires). } from '@triggery/core';
const inspector const inspector: InspectorImpl = createInspector function createInspector(bufferSize: number): InspectorImplRing-buffer inspector. `record` is O(1) — writes into a fixed-size slot array
with a wrap-around index, no `unshift`/`shift` allocations. `getBuffer`
materializes a newest-first array on demand (rare relative to fires). (50);
const latest const latest: TriggerInspectSnapshot | undefined = inspector const inspector: InspectorImpl .getLastForTrigger function getLastForTrigger(triggerId: string): TriggerInspectSnapshot | undefined ('chat:new-message');
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) (latest const latest: TriggerInspectSnapshot | undefined ?.status status: "fired" | "skipped" | "errored" | "aborted" | undefined );Subscribe and unsubscribe
Section titled “Subscribe and unsubscribe”import { createInspector function createInspector(bufferSize: number): InspectorImplRing-buffer inspector. `record` is O(1) — writes into a fixed-size slot array
with a wrap-around index, no `unshift`/`shift` allocations. `getBuffer`
materializes a newest-first array on demand (rare relative to fires). } from '@triggery/core';
const inspector const inspector: InspectorImpl = createInspector function createInspector(bufferSize: number): InspectorImplRing-buffer inspector. `record` is O(1) — writes into a fixed-size slot array
with a wrap-around index, no `unshift`/`shift` allocations. `getBuffer`
materializes a newest-first array on demand (rare relative to fires). (50);
const unsubscribe const unsubscribe: () => void = inspector const inspector: InspectorImpl .subscribe function subscribe(listener: (snapshot: TriggerInspectSnapshot) => void): () => void (snapshot snapshot: TriggerInspectSnapshot => {
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) (snapshot snapshot: TriggerInspectSnapshot .triggerId triggerId: string , snapshot snapshot: TriggerInspectSnapshot .status status: "fired" | "skipped" | "errored" | "aborted" );
});
// Later, when the panel unmounts:
unsubscribe const unsubscribe: () => void ();Related
Section titled “Related” createRuntime Pass `inspectorBufferSize` to control the standard inspector.
useInspectHistory React hook over the inspector buffer.
TriggerInspectSnapshot Snapshot shape.
Inspector guide What the inspector tracks and how to render it.