@triggery/mobx 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 +9 -0
- package/LICENSE +21 -0
- package/README.md +74 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/package.json +81 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @triggery/mobx
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
First public preview release.
|
|
6
|
+
|
|
7
|
+
MobX adapter for Triggery — read observable state from a trigger condition with no reaction setup
|
|
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,74 @@
|
|
|
1
|
+
# @triggery/mobx
|
|
2
|
+
|
|
3
|
+
Read [MobX](https://mobx.js.org) observable state from a Triggery condition without engaging MobX dependency tracking on the host component.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @triggery/core @triggery/react @triggery/mobx mobx
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { makeAutoObservable } from 'mobx';
|
|
15
|
+
import { createTrigger } from '@triggery/core';
|
|
16
|
+
import { useMobxCondition } from '@triggery/mobx';
|
|
17
|
+
|
|
18
|
+
class SettingsStore {
|
|
19
|
+
sound = true;
|
|
20
|
+
notifications = true;
|
|
21
|
+
constructor() {
|
|
22
|
+
makeAutoObservable(this);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const settings = new SettingsStore();
|
|
27
|
+
|
|
28
|
+
const messageTrigger = createTrigger<{
|
|
29
|
+
events: { 'new-message': { text: string } };
|
|
30
|
+
conditions: { settings: { sound: boolean; notifications: boolean } };
|
|
31
|
+
actions: { showToast: { body: string } };
|
|
32
|
+
}>({
|
|
33
|
+
id: 'message-received',
|
|
34
|
+
events: ['new-message'],
|
|
35
|
+
required: ['settings'],
|
|
36
|
+
handler({ event, conditions, actions }) {
|
|
37
|
+
if (!conditions.settings.notifications) return;
|
|
38
|
+
actions.showToast?.({ body: event.payload.text });
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
function SettingsBridge() {
|
|
43
|
+
useMobxCondition(messageTrigger, 'settings', () => ({
|
|
44
|
+
sound: settings.sound,
|
|
45
|
+
notifications: settings.notifications,
|
|
46
|
+
}));
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## How it works
|
|
52
|
+
|
|
53
|
+
The `read` function runs **only** when a trigger fires. MobX dependency tracking (`autorun`, `reaction`, `observer`) is not engaged from the hook, so:
|
|
54
|
+
|
|
55
|
+
* No component re-renders from this hook.
|
|
56
|
+
* No subscriber stays alive between fires.
|
|
57
|
+
|
|
58
|
+
If components also need to render the observable, wrap them in `observer` (or use `useObserver` from `mobx-react-lite`) — the two paths are orthogonal.
|
|
59
|
+
|
|
60
|
+
## API
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
useMobxCondition<S, K>(
|
|
64
|
+
trigger: Trigger<S>,
|
|
65
|
+
name: K,
|
|
66
|
+
read: () => ConditionMap<S>[K],
|
|
67
|
+
): void
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`read` is a plain function. Use `.get()` on boxes, dot-access on `observable.object`, etc. — exactly as you'd read MobX state anywhere else.
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TriggerSchema, ConditionKey, Trigger, ConditionMap } from '@triggery/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wire a MobX-tracked value into a Triggery condition.
|
|
5
|
+
*
|
|
6
|
+
* The runtime is pull-only — the `read` getter runs **only** when a trigger
|
|
7
|
+
* fires, not when the observable changes. MobX dependency tracking (`autorun`,
|
|
8
|
+
* `reaction`, `observer`) is _not_ engaged from this hook, so the trigger
|
|
9
|
+
* pipeline doesn't trip any auto-rerender on the host component.
|
|
10
|
+
*
|
|
11
|
+
* If you also need the same value in JSX, wrap that component in `observer`
|
|
12
|
+
* (or use `useObserver` from `mobx-react-lite`) — the two paths are
|
|
13
|
+
* orthogonal.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { makeAutoObservable } from 'mobx';
|
|
18
|
+
* import { useMobxCondition } from '@triggery/mobx';
|
|
19
|
+
*
|
|
20
|
+
* class SettingsStore {
|
|
21
|
+
* sound = true;
|
|
22
|
+
* notifications = true;
|
|
23
|
+
* constructor() { makeAutoObservable(this); }
|
|
24
|
+
* }
|
|
25
|
+
* const settings = new SettingsStore();
|
|
26
|
+
*
|
|
27
|
+
* function SettingsBridge() {
|
|
28
|
+
* useMobxCondition(messageTrigger, 'settings', () => ({
|
|
29
|
+
* sound: settings.sound,
|
|
30
|
+
* notifications: settings.notifications,
|
|
31
|
+
* }));
|
|
32
|
+
* return null;
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param read Plain function that reads the observable(s). Called on every
|
|
37
|
+
* fire of the trigger. Use `.get()` on boxes, dot-access on
|
|
38
|
+
* `observable.object`, etc. — same as you'd use anywhere in MobX.
|
|
39
|
+
*/
|
|
40
|
+
declare function useMobxCondition<S extends TriggerSchema, K extends ConditionKey<S>>(trigger: Trigger<S>, name: K, read: () => ConditionMap<S>[K]): void;
|
|
41
|
+
|
|
42
|
+
export { useMobxCondition };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useCondition } from '@triggery/react';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
function useMobxCondition(trigger, name, read) {
|
|
5
|
+
useCondition(trigger, name, read, [read]);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { useMobxCondition };
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAwCO,SAAS,gBAAA,CACd,OAAA,EACA,IAAA,EACA,IAAA,EACM;AACN,EAAA,YAAA,CAAa,OAAA,EAAS,IAAA,EAAM,IAAA,EAAM,CAAC,IAAI,CAAC,CAAA;AAC1C","file":"index.js","sourcesContent":["import type { ConditionKey, ConditionMap, Trigger, TriggerSchema } from '@triggery/core';\nimport { useCondition } from '@triggery/react';\n\n/**\n * Wire a MobX-tracked value into a Triggery condition.\n *\n * The runtime is pull-only — the `read` getter runs **only** when a trigger\n * fires, not when the observable changes. MobX dependency tracking (`autorun`,\n * `reaction`, `observer`) is _not_ engaged from this hook, so the trigger\n * pipeline doesn't trip any auto-rerender on the host component.\n *\n * If you also need the same value in JSX, wrap that component in `observer`\n * (or use `useObserver` from `mobx-react-lite`) — the two paths are\n * orthogonal.\n *\n * @example\n * ```tsx\n * import { makeAutoObservable } from 'mobx';\n * import { useMobxCondition } from '@triggery/mobx';\n *\n * class SettingsStore {\n * sound = true;\n * notifications = true;\n * constructor() { makeAutoObservable(this); }\n * }\n * const settings = new SettingsStore();\n *\n * function SettingsBridge() {\n * useMobxCondition(messageTrigger, 'settings', () => ({\n * sound: settings.sound,\n * notifications: settings.notifications,\n * }));\n * return null;\n * }\n * ```\n *\n * @param read Plain function that reads the observable(s). Called on every\n * fire of the trigger. Use `.get()` on boxes, dot-access on\n * `observable.object`, etc. — same as you'd use anywhere in MobX.\n */\nexport function useMobxCondition<S extends TriggerSchema, K extends ConditionKey<S>>(\n trigger: Trigger<S>,\n name: K,\n read: () => ConditionMap<S>[K],\n): void {\n useCondition(trigger, name, read, [read]);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@triggery/mobx",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MobX adapter for Triggery — read observable state from a trigger condition with no reaction setup",
|
|
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/mobx"
|
|
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
|
+
"mobx",
|
|
27
|
+
"adapter",
|
|
28
|
+
"react",
|
|
29
|
+
"observable"
|
|
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
|
+
"mobx": "^6.0.0",
|
|
56
|
+
"react": ">=18.0.0",
|
|
57
|
+
"@triggery/react": "0.1.0",
|
|
58
|
+
"@triggery/core": "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
|
+
"mobx": "^6.15.3",
|
|
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
|
+
}
|