createInspector
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”createInspector re-exports through the main @triggery/core entry for backwards compatibility, but the @triggery/core/inspect subpath is the canonical home in v0.10+ — it keeps the inspector code out of the main bundle for apps that don’t reach for it. The same subpath also exports createInspectorFactory() (a thin wrapper that returns (bufferSize) => createInspector(bufferSize)) — pass it as createRuntime({ inspector: createInspectorFactory() }) when you want the runtime to instantiate the inspector on demand, with no static dependency from the main entry.
Signature
Section titled “Signature”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. |