@triggery/jotai 0.1.0

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @triggery/jotai
2
+
3
+ ## 0.1.0
4
+
5
+ First public preview release.
6
+
7
+ Jotai adapter for Triggery — read an atom's value from a trigger condition without subscribing the host component to atom updates
8
+
9
+ See the [repository-level CHANGELOG](../../CHANGELOG.md#010--2026-05-16) for the full set of packages and the umbrella feature list. Future entries on this file are appended automatically by changesets.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aleksey Skhomenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @triggery/jotai
2
+
3
+ Read a [Jotai](https://jotai.org) atom from a Triggery condition without subscribing the host component to atom updates.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @triggery/core @triggery/react @triggery/jotai jotai
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```tsx
14
+ import { atom, createStore } from 'jotai';
15
+ import { createTrigger } from '@triggery/core';
16
+ import { useJotaiCondition } from '@triggery/jotai';
17
+
18
+ type Settings = { sound: boolean; notifications: boolean };
19
+
20
+ const settingsAtom = atom<Settings>({ sound: true, notifications: true });
21
+ const store = createStore();
22
+
23
+ const messageTrigger = createTrigger<{
24
+ events: { 'new-message': { text: string } };
25
+ conditions: { settings: Settings };
26
+ actions: { showToast: { body: string } };
27
+ }>({
28
+ id: 'message-received',
29
+ events: ['new-message'],
30
+ required: ['settings'],
31
+ handler({ event, conditions, actions }) {
32
+ if (!conditions.settings.notifications) return;
33
+ actions.showToast?.({ body: event.payload.text });
34
+ },
35
+ });
36
+
37
+ function SettingsBridge() {
38
+ useJotaiCondition(messageTrigger, 'settings', store, settingsAtom);
39
+ return null;
40
+ }
41
+ ```
42
+
43
+ With a selector for projection:
44
+
45
+ ```ts
46
+ useJotaiCondition(messageTrigger, 'settings', store, profileAtom, (p) => p.settings);
47
+ ```
48
+
49
+ ## How it works
50
+
51
+ Pull-only: `store.get(atom)` runs **only** when a trigger fires, not on every atom update. The host component is never re-rendered by atom changes — that's `useAtomValue`'s job and lives in the components that actually render the value.
52
+
53
+ ## API
54
+
55
+ ```ts
56
+ useJotaiCondition<V, S, K>(
57
+ trigger: Trigger<S>,
58
+ name: K,
59
+ store: { get<V>(atom): V },
60
+ atom: Atom<V>,
61
+ selector?: (value: V) => ConditionMap<S>[K],
62
+ ): void
63
+ ```
64
+
65
+ ## License
66
+
67
+ MIT
@@ -0,0 +1,47 @@
1
+ import { TriggerSchema, ConditionKey, Trigger, ConditionMap } from '@triggery/core';
2
+
3
+ /**
4
+ * Minimal Jotai atom shape we depend on. Matches the structurally typed atom
5
+ * returned by `atom()` from `jotai/vanilla`.
6
+ */
7
+ interface JotaiAtomLike<V> {
8
+ read: unknown;
9
+ toString(): string;
10
+ debugLabel?: string;
11
+ init?: V;
12
+ }
13
+ /**
14
+ * Minimal Jotai store shape (`createStore()` from `jotai/vanilla`).
15
+ */
16
+ interface JotaiStoreLike {
17
+ get<V>(atom: JotaiAtomLike<V>): V;
18
+ }
19
+ /**
20
+ * Wire a Jotai atom into a Triggery condition.
21
+ *
22
+ * The runtime is pull-only — `store.get(atom)` runs **only** when a trigger
23
+ * fires, not when the atom updates. The hook does not subscribe the component
24
+ * to the atom; if a separate component needs the same value in JSX, use
25
+ * `useAtomValue` from `jotai` alongside.
26
+ *
27
+ * @example
28
+ * ```tsx
29
+ * import { atom, createStore } from 'jotai';
30
+ * import { useJotaiCondition } from '@triggery/jotai';
31
+ *
32
+ * const settingsAtom = atom({ sound: true, notifications: true });
33
+ * const store = createStore();
34
+ *
35
+ * function SettingsBridge() {
36
+ * useJotaiCondition(messageTrigger, 'settings', store, settingsAtom);
37
+ * return null;
38
+ * }
39
+ * ```
40
+ *
41
+ * @param selector Optional projection of the atom's value into the condition
42
+ * shape. Defaults to identity, requiring the atom value type
43
+ * to match `ConditionMap<S>[K]`.
44
+ */
45
+ declare function useJotaiCondition<V, S extends TriggerSchema, K extends ConditionKey<S>>(trigger: Trigger<S>, name: K, store: JotaiStoreLike, atom: JotaiAtomLike<V>, selector?: (value: V) => ConditionMap<S>[K]): void;
46
+
47
+ export { type JotaiAtomLike, type JotaiStoreLike, useJotaiCondition };
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ import { useCondition } from '@triggery/react';
2
+
3
+ // src/index.ts
4
+ function useJotaiCondition(trigger, name, store, atom, selector) {
5
+ useCondition(
6
+ trigger,
7
+ name,
8
+ () => {
9
+ const value = store.get(atom);
10
+ return selector ? selector(value) : value;
11
+ },
12
+ [store, atom, selector]
13
+ );
14
+ }
15
+
16
+ export { useJotaiCondition };
17
+ //# sourceMappingURL=index.js.map
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AA+CO,SAAS,iBAAA,CACd,OAAA,EACA,IAAA,EACA,KAAA,EACA,MACA,QAAA,EACM;AACN,EAAA,YAAA;AAAA,IACE,OAAA;AAAA,IACA,IAAA;AAAA,IACA,MAAM;AACJ,MAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,GAAA,CAAI,IAAI,CAAA;AAC5B,MAAA,OAAO,QAAA,GAAW,QAAA,CAAS,KAAK,CAAA,GAAK,KAAA;AAAA,IACvC,CAAA;AAAA,IACA,CAAC,KAAA,EAAO,IAAA,EAAM,QAAQ;AAAA,GACxB;AACF","file":"index.js","sourcesContent":["import type { ConditionKey, ConditionMap, Trigger, TriggerSchema } from '@triggery/core';\nimport { useCondition } from '@triggery/react';\n\n/**\n * Minimal Jotai atom shape we depend on. Matches the structurally typed atom\n * returned by `atom()` from `jotai/vanilla`.\n */\nexport interface JotaiAtomLike<V> {\n read: unknown;\n toString(): string;\n debugLabel?: string;\n init?: V;\n}\n\n/**\n * Minimal Jotai store shape (`createStore()` from `jotai/vanilla`).\n */\nexport interface JotaiStoreLike {\n get<V>(atom: JotaiAtomLike<V>): V;\n}\n\n/**\n * Wire a Jotai atom into a Triggery condition.\n *\n * The runtime is pull-only — `store.get(atom)` runs **only** when a trigger\n * fires, not when the atom updates. The hook does not subscribe the component\n * to the atom; if a separate component needs the same value in JSX, use\n * `useAtomValue` from `jotai` alongside.\n *\n * @example\n * ```tsx\n * import { atom, createStore } from 'jotai';\n * import { useJotaiCondition } from '@triggery/jotai';\n *\n * const settingsAtom = atom({ sound: true, notifications: true });\n * const store = createStore();\n *\n * function SettingsBridge() {\n * useJotaiCondition(messageTrigger, 'settings', store, settingsAtom);\n * return null;\n * }\n * ```\n *\n * @param selector Optional projection of the atom's value into the condition\n * shape. Defaults to identity, requiring the atom value type\n * to match `ConditionMap<S>[K]`.\n */\nexport function useJotaiCondition<V, S extends TriggerSchema, K extends ConditionKey<S>>(\n trigger: Trigger<S>,\n name: K,\n store: JotaiStoreLike,\n atom: JotaiAtomLike<V>,\n selector?: (value: V) => ConditionMap<S>[K],\n): void {\n useCondition(\n trigger,\n name,\n () => {\n const value = store.get(atom);\n return selector ? selector(value) : (value as unknown as ConditionMap<S>[K]);\n },\n [store, atom, selector],\n );\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@triggery/jotai",
3
+ "version": "0.1.0",
4
+ "description": "Jotai adapter for Triggery — read an atom's value from a trigger condition without subscribing the host component to atom updates",
5
+ "license": "MIT",
6
+ "author": "Aleksey Skhomenko",
7
+ "homepage": "https://triggeryjs.github.io/triggery",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/triggeryjs/triggery.git",
11
+ "directory": "packages/jotai"
12
+ },
13
+ "bugs": "https://github.com/triggeryjs/triggery/issues",
14
+ "funding": [
15
+ {
16
+ "type": "patreon",
17
+ "url": "https://www.patreon.com/triggery"
18
+ },
19
+ {
20
+ "type": "boosty",
21
+ "url": "https://boosty.to/triggery"
22
+ }
23
+ ],
24
+ "keywords": [
25
+ "triggery",
26
+ "jotai",
27
+ "adapter",
28
+ "react",
29
+ "atoms"
30
+ ],
31
+ "type": "module",
32
+ "main": "./dist/index.js",
33
+ "module": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "exports": {
36
+ ".": {
37
+ "source": "./src/index.ts",
38
+ "types": "./dist/index.d.ts",
39
+ "import": "./dist/index.js",
40
+ "default": "./dist/index.js"
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "files": [
45
+ "dist",
46
+ "README.md",
47
+ "LICENSE",
48
+ "CHANGELOG.md"
49
+ ],
50
+ "sideEffects": false,
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "peerDependencies": {
55
+ "jotai": "^2.0.0",
56
+ "react": ">=18.0.0",
57
+ "@triggery/core": "0.1.0",
58
+ "@triggery/react": "0.1.0"
59
+ },
60
+ "devDependencies": {
61
+ "@testing-library/react": "^16.3.2",
62
+ "@types/react": "^19.2.14",
63
+ "happy-dom": "^20.9.0",
64
+ "jotai": "^2.10.0",
65
+ "react": "^19.2.6",
66
+ "react-dom": "^19.2.6",
67
+ "tsup": "^8.5.1",
68
+ "typescript": "^6.0.3",
69
+ "vitest": "^4.1.6",
70
+ "@triggery/core": "0.1.0",
71
+ "@triggery/react": "0.1.0"
72
+ },
73
+ "scripts": {
74
+ "build": "tsup",
75
+ "dev": "tsup --watch",
76
+ "test": "vitest run",
77
+ "test:watch": "vitest",
78
+ "test:coverage": "vitest run --coverage",
79
+ "clean": "rm -rf dist *.tsbuildinfo"
80
+ }
81
+ }