@triggery/redux 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 +61 -0
- package/dist/index.d.ts +37 -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/redux
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
First public preview release.
|
|
6
|
+
|
|
7
|
+
Redux adapter for Triggery — read store state from a trigger condition without subscribing the component to re-renders
|
|
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,61 @@
|
|
|
1
|
+
# @triggery/redux
|
|
2
|
+
|
|
3
|
+
Read a [Redux](https://redux.js.org) store from a Triggery condition without subscribing the component to re-renders.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @triggery/core @triggery/react @triggery/redux redux
|
|
9
|
+
# (or @reduxjs/toolkit, which re-exports `createStore`)
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { configureStore } from '@reduxjs/toolkit';
|
|
16
|
+
import { createTrigger } from '@triggery/core';
|
|
17
|
+
import { useReduxCondition } from '@triggery/redux';
|
|
18
|
+
|
|
19
|
+
const store = configureStore({ reducer: rootReducer });
|
|
20
|
+
|
|
21
|
+
type State = ReturnType<typeof store.getState>;
|
|
22
|
+
type Settings = State['settings'];
|
|
23
|
+
|
|
24
|
+
const messageTrigger = createTrigger<{
|
|
25
|
+
events: { 'new-message': { text: string } };
|
|
26
|
+
conditions: { settings: Settings };
|
|
27
|
+
actions: { showToast: { body: string } };
|
|
28
|
+
}>({
|
|
29
|
+
id: 'message-received',
|
|
30
|
+
events: ['new-message'],
|
|
31
|
+
required: ['settings'],
|
|
32
|
+
handler({ event, conditions, actions }) {
|
|
33
|
+
if (!conditions.settings.notifications) return;
|
|
34
|
+
actions.showToast?.({ body: event.payload.text });
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function SettingsBridge() {
|
|
39
|
+
useReduxCondition(messageTrigger, 'settings', store, (s) => s.settings);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## How it works
|
|
45
|
+
|
|
46
|
+
Triggery is pull-only: the selector runs **only** when a trigger fires, not on every dispatch. The hook does not subscribe the component to the store — so dispatches never re-render the bridge component. If a separate component needs the same slice in its JSX, use `useSelector` from `react-redux` alongside.
|
|
47
|
+
|
|
48
|
+
## API
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
useReduxCondition<T, S, K>(
|
|
52
|
+
trigger: Trigger<S>,
|
|
53
|
+
name: K,
|
|
54
|
+
store: { getState(): T },
|
|
55
|
+
selector: (state: T) => ConditionMap<S>[K],
|
|
56
|
+
): void
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { TriggerSchema, ConditionKey, Trigger, ConditionMap } from '@triggery/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimal Redux store contract we depend on. Matches what `createStore`,
|
|
5
|
+
* `configureStore` and any other Redux-compatible store expose, so we don't
|
|
6
|
+
* import Redux itself.
|
|
7
|
+
*/
|
|
8
|
+
interface ReduxStoreLike<T> {
|
|
9
|
+
getState(): T;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Wire a Redux store into a Triggery condition.
|
|
13
|
+
*
|
|
14
|
+
* The runtime is pull-only — `selector(store.getState())` runs when a trigger
|
|
15
|
+
* fires, not on every dispatch. The hook does **not** subscribe the component
|
|
16
|
+
* to the store; if you also need the same slice in JSX, use `useSelector`
|
|
17
|
+
* from `react-redux` alongside.
|
|
18
|
+
*
|
|
19
|
+
* The trigger always sees the latest state at fire-time, regardless of how
|
|
20
|
+
* the component tree re-rendered (or didn't).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { configureStore } from '@reduxjs/toolkit';
|
|
25
|
+
* import { useReduxCondition } from '@triggery/redux';
|
|
26
|
+
*
|
|
27
|
+
* const store = configureStore({ reducer: rootReducer });
|
|
28
|
+
*
|
|
29
|
+
* function SettingsBridge() {
|
|
30
|
+
* useReduxCondition(messageTrigger, 'settings', store, (s) => s.settings);
|
|
31
|
+
* return null;
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
declare function useReduxCondition<T, S extends TriggerSchema, K extends ConditionKey<S>>(trigger: Trigger<S>, name: K, store: ReduxStoreLike<T>, selector: (state: T) => ConditionMap<S>[K]): void;
|
|
36
|
+
|
|
37
|
+
export { type ReduxStoreLike, useReduxCondition };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useCondition } from '@triggery/react';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
function useReduxCondition(trigger, name, store, selector) {
|
|
5
|
+
useCondition(trigger, name, () => selector(store.getState()), [store, selector]);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { useReduxCondition };
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAoCO,SAAS,iBAAA,CACd,OAAA,EACA,IAAA,EACA,KAAA,EACA,QAAA,EACM;AACN,EAAA,YAAA,CAAa,OAAA,EAAS,IAAA,EAAM,MAAM,QAAA,CAAS,KAAA,CAAM,QAAA,EAAU,CAAA,EAAG,CAAC,KAAA,EAAO,QAAQ,CAAC,CAAA;AACjF","file":"index.js","sourcesContent":["import type { ConditionKey, ConditionMap, Trigger, TriggerSchema } from '@triggery/core';\nimport { useCondition } from '@triggery/react';\n\n/**\n * Minimal Redux store contract we depend on. Matches what `createStore`,\n * `configureStore` and any other Redux-compatible store expose, so we don't\n * import Redux itself.\n */\nexport interface ReduxStoreLike<T> {\n getState(): T;\n}\n\n/**\n * Wire a Redux store into a Triggery condition.\n *\n * The runtime is pull-only — `selector(store.getState())` runs when a trigger\n * fires, not on every dispatch. The hook does **not** subscribe the component\n * to the store; if you also need the same slice in JSX, use `useSelector`\n * from `react-redux` alongside.\n *\n * The trigger always sees the latest state at fire-time, regardless of how\n * the component tree re-rendered (or didn't).\n *\n * @example\n * ```ts\n * import { configureStore } from '@reduxjs/toolkit';\n * import { useReduxCondition } from '@triggery/redux';\n *\n * const store = configureStore({ reducer: rootReducer });\n *\n * function SettingsBridge() {\n * useReduxCondition(messageTrigger, 'settings', store, (s) => s.settings);\n * return null;\n * }\n * ```\n */\nexport function useReduxCondition<T, S extends TriggerSchema, K extends ConditionKey<S>>(\n trigger: Trigger<S>,\n name: K,\n store: ReduxStoreLike<T>,\n selector: (state: T) => ConditionMap<S>[K],\n): void {\n useCondition(trigger, name, () => selector(store.getState()), [store, selector]);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@triggery/redux",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Redux adapter for Triggery — read store state from a trigger condition without subscribing the component to re-renders",
|
|
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/redux"
|
|
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
|
+
"redux",
|
|
27
|
+
"adapter",
|
|
28
|
+
"react",
|
|
29
|
+
"state"
|
|
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
|
+
"react": ">=18.0.0",
|
|
56
|
+
"redux": "^4.0.0 || ^5.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
|
+
"react": "^19.2.6",
|
|
65
|
+
"react-dom": "^19.2.6",
|
|
66
|
+
"redux": "^5.0.1",
|
|
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
|
+
}
|