@triggery/react 0.1.1 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +151 -11
  3. package/package.json +6 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @triggery/react
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - f23e155: Filled out the quick-start sections in the npm package READMEs that adopters land on first.
8
+
9
+ - `@triggery/core` README now contains a three-tab quick-start (React / Solid / Vue) with concrete `pnpm add` commands and runnable code, plus pointers to the per-binding README for the full walkthrough.
10
+ - `@triggery/react` README — was a stub. Now has the full four-file scenario (trigger + provider + Chat + Toast) ready to copy-paste, exactly mirroring the Solid and Vue examples.
11
+
12
+ Linked-bundle bump so the binding READMEs stay aligned with the core release; no code or API changes.
13
+
14
+ - 3385f5b: Every package README now ends with a tailored **Related packages** section and a consistent `## License` footer.
15
+
16
+ - Adapter packages (`zustand`, `redux`, `jotai`, `mobx`, `reatom`, `signals`, `query`) link to `core` + `react` (required peers) plus 2-3 alternative adapters so adopters can swap them out without re-reading the whole repo.
17
+ - Event-source packages (`dom`, `socket`) cross-link.
18
+ - DevTools packages (`devtools-redux`, `devtools-panel`, `devtools-bridge`) cross-link.
19
+ - Tooling packages (`eslint-plugin`, `codemod`, `cli`) cross-link.
20
+ - Bindings (`react`, `solid`, `vue`) link to each other so users mid-migration know there's a sibling with the same hook API.
21
+ - `@triggery/core/src/index.ts` JSDoc header had stale wording ("orchestration runtime for React business logic") — replaced with framework-agnostic phrasing matching the README.
22
+
23
+ No code or API changes. Drop-in patch.
24
+
25
+ - Updated dependencies [f23e155]
26
+ - Updated dependencies [3385f5b]
27
+ - @triggery/core@0.1.2
28
+
3
29
  ## 0.1.1
4
30
 
5
31
  ### Patch Changes
package/README.md CHANGED
@@ -1,22 +1,162 @@
1
1
  # @triggery/react
2
2
 
3
- React bindings for [Triggery](https://github.com/triggeryjs/triggery).
4
-
5
- Provides:
6
-
7
- - `useEvent(trigger, 'eventName')` — get a typed event emitter.
8
- - `useCondition(trigger, 'name', () => value, [deps])` — register pull-based condition data.
9
- - `useAction(trigger, 'name', handler)` — register an action executor.
10
- - `useInlineTrigger({ on, do, if?, required? })` — define an inline trigger inside a component.
11
- - `<TriggerScope id="...">` — isolate registrations to a scope.
12
- - `<TriggerRuntimeProvider runtime={...}>` — attach a custom runtime.
3
+ React 18+/19 bindings for [Triggery](https://github.com/triggeryjs/triggery). Same `useEvent` / `useCondition` / `useAction` shape as `@triggery/solid` and `@triggery/vue`. **Zero runtime dependencies** — the binding is a thin lifecycle layer over `@triggery/core`.
13
4
 
14
5
  ## Install
15
6
 
16
7
  ```bash
17
- pnpm add @triggery/react @triggery/core
8
+ pnpm add @triggery/core @triggery/react
9
+ # pnpm / npm / yarn / bun all work
10
+ ```
11
+
12
+ `react` and `react-dom` are peer deps (≥ 18.0.0).
13
+
14
+ ## Quick start
15
+
16
+ A complete scenario lives across four small files. The trigger reads like a spec, components only know about their own port.
17
+
18
+ ### 1. Define the trigger
19
+
20
+ ```ts
21
+ // src/triggers/message.trigger.ts
22
+ import { createTrigger } from '@triggery/core';
23
+
24
+ type Settings = { sound: boolean; notifications: boolean };
25
+
26
+ export const messageTrigger = createTrigger<{
27
+ events: { 'new-message': { text: string; author: string } };
28
+ conditions: { settings: Settings };
29
+ actions: { showToast: { title: string; body: string } };
30
+ }>({
31
+ id: 'message-received',
32
+ events: ['new-message'],
33
+ required: ['settings'],
34
+ handler({ event, conditions, actions }) {
35
+ if (!conditions.settings.notifications) return;
36
+ actions.showToast?.({
37
+ title: event.payload.author,
38
+ body: event.payload.text,
39
+ });
40
+ },
41
+ });
18
42
  ```
19
43
 
44
+ ### 2. Wrap the tree
45
+
46
+ ```tsx
47
+ // src/main.tsx
48
+ import { createRuntime } from '@triggery/core';
49
+ import { TriggerRuntimeProvider } from '@triggery/react';
50
+ import { StrictMode } from 'react';
51
+ import { createRoot } from 'react-dom/client';
52
+ import { App } from './App.tsx';
53
+
54
+ const runtime = createRuntime();
55
+
56
+ createRoot(document.getElementById('root')!).render(
57
+ <StrictMode>
58
+ <TriggerRuntimeProvider runtime={runtime}>
59
+ <App />
60
+ </TriggerRuntimeProvider>
61
+ </StrictMode>,
62
+ );
63
+ ```
64
+
65
+ ### 3. Wire components into ports
66
+
67
+ ```tsx
68
+ // src/App.tsx
69
+ import { useAction, useCondition, useEvent } from '@triggery/react';
70
+ import { useState } from 'react';
71
+ import { messageTrigger } from './triggers/message.trigger.ts';
72
+
73
+ function SettingsProvider() {
74
+ const [settings] = useState({ sound: true, notifications: true });
75
+ useCondition(messageTrigger, 'settings', () => settings, [settings]);
76
+ return null;
77
+ }
78
+
79
+ function Chat() {
80
+ const fire = useEvent(messageTrigger, 'new-message');
81
+ return (
82
+ <button type="button" onClick={() => fire({ text: 'hi', author: 'Alice' })}>
83
+ send
84
+ </button>
85
+ );
86
+ }
87
+
88
+ function Toast() {
89
+ useAction(messageTrigger, 'showToast', ({ title, body }) => {
90
+ console.log(`[${title}] ${body}`);
91
+ });
92
+ return null;
93
+ }
94
+
95
+ export function App() {
96
+ return (
97
+ <>
98
+ <SettingsProvider />
99
+ <Chat />
100
+ <Toast />
101
+ </>
102
+ );
103
+ }
104
+ ```
105
+
106
+ Click the button — `Toast` gets the action. Toggle `settings.notifications` to false — silent.
107
+
108
+ For a runnable version: [`examples/vite-react-counter`](https://github.com/triggeryjs/triggery/tree/main/examples/vite-react-counter) or open it in StackBlitz from the [main README](https://github.com/triggeryjs/triggery#try-it-in-5-seconds).
109
+
110
+ ## API
111
+
112
+ ### `<TriggerRuntimeProvider runtime>`
113
+
114
+ Provides a `Runtime` to the subtree. Required for any descendant using the hooks below. You normally create one runtime per app, but isolated runtimes (per-feature, per-tab, per-test) are fully supported.
115
+
116
+ ### `<TriggerScope id>`
117
+
118
+ Scopes condition / action registrations to triggers that declared the same `scope` id. Triggers without a scope see only registrations made outside any `<TriggerScope>`.
119
+
120
+ ### `useEvent(trigger, eventName)`
121
+
122
+ Returns a stable `(payload) => void` emitter. Identity is stable across renders.
123
+
124
+ ### `useCondition(trigger, name, getter, deps?)`
125
+
126
+ Registers a getter the runtime invokes **at fire time**. Pull-only — your component never re-renders because of the trigger. `deps` work like `useMemo` — when they change the runtime sees the fresh closure.
127
+
128
+ ### `useAction(trigger, name, handler)`
129
+
130
+ Registers an action handler. Last-mount-wins with a DEV warn-once on collision.
131
+
132
+ ### `useInlineTrigger({ on, do, id? })`
133
+
134
+ Defines a one-off trigger inline inside a component — useful for tiny analytics taps or modal-stack coordination that doesn't need its own `*.trigger.ts` file. The trigger lives for the lifetime of the component.
135
+
136
+ ### `useInspect(trigger)` / `useInspectHistory(limit?)`
137
+
138
+ Read the latest snapshot of a trigger, or subscribe to the runtime's inspector ring buffer. Pair with `<InspectorView>` from `@triggery/devtools-panel` for a turnkey debug UI.
139
+
140
+ ### `createNamedHooks(trigger)`
141
+
142
+ Returns `{ useFooEvent, useBarCondition, useBazAction }` named hooks derived from the trigger schema — purely for code readability in larger files.
143
+
144
+ ## Documentation
145
+
146
+ Full documentation, recipes and API reference at [https://triggeryjs.github.io/packages/react/](https://triggeryjs.github.io/packages/react/).
147
+
148
+ ## Related packages
149
+
150
+ - [`@triggery/core`](https://www.npmjs.com/package/@triggery/core) — Required peer — the runtime this binding wraps.
151
+ - [`@triggery/solid`](https://www.npmjs.com/package/@triggery/solid) — SolidJS variant with the same hook API.
152
+ - [`@triggery/vue`](https://www.npmjs.com/package/@triggery/vue) — Vue 3 variant with the same hook API.
153
+ - [`@triggery/zustand`](https://www.npmjs.com/package/@triggery/zustand) — Adapter: read a Zustand store from a condition.
154
+ - [`@triggery/redux`](https://www.npmjs.com/package/@triggery/redux) — Adapter: read a Redux store from a condition.
155
+ - [`@triggery/jotai`](https://www.npmjs.com/package/@triggery/jotai) — Adapter: read a Jotai atom from a condition.
156
+ - [`@triggery/query`](https://www.npmjs.com/package/@triggery/query) — Adapter: read a TanStack Query cache entry.
157
+
158
+ See the [full package list](https://github.com/triggeryjs/triggery#packages) in the repo README.
159
+
20
160
  ## License
21
161
 
22
162
  MIT &copy; Aleksey Skhomenko
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@triggery/react",
3
- "version": "0.1.1",
3
+ "version": "0.9.1",
4
4
  "description": "React 18+/19 bindings for Triggery — useEvent / useCondition / useAction / useInlineTrigger / useInspect hooks + <TriggerRuntimeProvider> / <TriggerScope>. Zero runtime dependencies.",
5
5
  "license": "MIT",
6
6
  "author": "Aleksey Skhomenko",
7
- "homepage": "https://triggeryjs.github.io/triggery",
7
+ "homepage": "https://triggeryjs.github.io",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/triggeryjs/triggery.git",
@@ -54,7 +54,7 @@
54
54
  },
55
55
  "peerDependencies": {
56
56
  "react": ">=18.0.0",
57
- "@triggery/core": "0.1.1"
57
+ "@triggery/core": "0.9.1"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@testing-library/react": "^16.3.2",
@@ -65,8 +65,10 @@
65
65
  "tsup": "^8.5.1",
66
66
  "typescript": "^6.0.3",
67
67
  "vitest": "^4.1.6",
68
- "@triggery/core": "0.1.1"
68
+ "@triggery/core": "0.9.1"
69
69
  },
70
+ "llms": "https://triggeryjs.github.io/llms.txt",
71
+ "llmsFull": "https://triggeryjs.github.io/llms-full.txt",
70
72
  "scripts": {
71
73
  "build": "tsup",
72
74
  "dev": "tsup --watch",