@triggery/core
The runtime that powers every Triggery binding. Framework-agnostic, zero runtime dependencies, runs anywhere JavaScript runs (browser, Node, Workers, React Native, edge).
Install
Section titled “Install”pnpm add @triggery/core npm install @triggery/core yarn add @triggery/core bun add @triggery/core What’s inside
Section titled “What’s inside”| Export | Purpose |
|---|---|
createTrigger | Declare a scenario (events, conditions, required, handler). |
createRuntime | Instantiate an isolated runtime. |
getDefaultRuntime / setDefaultRuntime | Global singleton helpers. |
createCheck | Build the check.is/all/any helpers for the handler context. |
createInspector | Custom ring-buffer inspector. |
createScheduler | Build a custom scheduler. |
| All public types | TriggerSchema, TriggerCtx, Middleware, ConcurrencyStrategy, … |
Quick example
Section titled “Quick example”That’s the runtime in isolation. In a real app you’d skip the manual registerAction — bindings do that through useAction.
Why “framework-agnostic”?
Section titled “Why “framework-agnostic”?”The runtime is a plain JavaScript object with a Map-based registry. It does not import React. It does not import a virtual DOM. It can run:
- In a web worker or service worker.
- In a Node.js process — CLI, server, edge function.
- In React Native (no DOM adapter needed for the runtime).
- In a vanilla HTML page with no bundler.
The same createTrigger({ … }) declaration runs unchanged in all of the above. Bindings (~50 lines each) wire useEvent / useCondition / useAction to the host framework’s lifecycle.
Features
Section titled “Features”- Indexed dispatch —
Map<eventKey, Trigger[]>, no full-table scans. required-gate — handler skipped (with inspector entry) until all required conditions are registered.- Concurrency strategies for async handlers:
take-latest(default),take-every,take-first,queue,exhaust,sync. - Action chains:
actions.debounce(ms).foo(p),actions.throttle,actions.defer,actions.queue. - Cascade safety — depth limit + cycle detection on
action → fireEventchains. - Middleware —
onFire,onBeforeMatch,onSkip,onActionStart,onActionEnd,onError,onCascade. - Inspector ring buffer — built-in, auto-disables in PROD by default. Opt-in via
@triggery/core/inspectfor the bundle-friendly factory pattern (v0.10+). - Last-write-wins ownership for conditions / actions with DEV warn-once.
- Pure ESM, side-effect-free, tree-shakable.
Bundle size
Section titled “Bundle size”~4.2 KB gzipped for the @triggery/core main entry (v0.10, production minification). With the @triggery/core/builder subpath bundled alongside it (the bundler deduplicates shared helpers), the combined cost lands at ~3.8 KB gz. Framework bindings add about 1 KB each on top.