@veams/status-quo 1.7.0 → 1.8.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/.turbo/turbo-test.log +115 -15
- package/CHANGELOG.md +2 -0
- package/README.md +51 -7
- package/dist/config/status-quo-config.d.ts +22 -1
- package/dist/config/status-quo-config.js +46 -2
- package/dist/config/status-quo-config.js.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.js +22 -2
- package/dist/index.js.map +1 -1
- package/dist/react/hooks/__tests__/state-provider.spec.js +2 -2
- package/dist/react/hooks/__tests__/state-provider.spec.js.map +1 -1
- package/dist/react/hooks/index.d.ts +6 -3
- package/dist/react/hooks/index.js +12 -3
- package/dist/react/hooks/index.js.map +1 -1
- package/dist/react/hooks/state-actions.d.ts +9 -1
- package/dist/react/hooks/state-actions.js +21 -2
- package/dist/react/hooks/state-actions.js.map +1 -1
- package/dist/react/hooks/state-factory.d.ts +7 -0
- package/dist/react/hooks/state-factory.js +23 -1
- package/dist/react/hooks/state-factory.js.map +1 -1
- package/dist/react/hooks/state-handler.d.ts +4 -0
- package/dist/react/hooks/state-handler.js +18 -1
- package/dist/react/hooks/state-handler.js.map +1 -1
- package/dist/react/hooks/state-provider.d.ts +18 -9
- package/dist/react/hooks/state-provider.js +25 -17
- package/dist/react/hooks/state-provider.js.map +1 -1
- package/dist/react/hooks/state-singleton.d.ts +8 -2
- package/dist/react/hooks/state-singleton.js +21 -3
- package/dist/react/hooks/state-singleton.js.map +1 -1
- package/dist/react/hooks/state-subscription-selector.d.ts +4 -0
- package/dist/react/hooks/state-subscription-selector.js +64 -8
- package/dist/react/hooks/state-subscription-selector.js.map +1 -1
- package/dist/react/hooks/state-subscription.d.ts +12 -0
- package/dist/react/hooks/state-subscription.js +49 -1
- package/dist/react/hooks/state-subscription.js.map +1 -1
- package/dist/react/index.d.ts +4 -1
- package/dist/react/index.js +5 -1
- package/dist/react/index.js.map +1 -1
- package/dist/store/__tests__/native-state-handler.spec.d.ts +1 -0
- package/dist/store/__tests__/native-state-handler.spec.js +210 -0
- package/dist/store/__tests__/native-state-handler.spec.js.map +1 -0
- package/dist/store/__tests__/observable-state-handler.spec.d.ts +7 -0
- package/dist/store/__tests__/observable-state-handler.spec.js.map +1 -1
- package/dist/store/base-state-handler.d.ts +42 -0
- package/dist/store/base-state-handler.js +73 -10
- package/dist/store/base-state-handler.js.map +1 -1
- package/dist/store/dev-tools.d.ts +42 -17
- package/dist/store/dev-tools.js +24 -8
- package/dist/store/dev-tools.js.map +1 -1
- package/dist/store/index.d.ts +7 -0
- package/dist/store/index.js +9 -0
- package/dist/store/index.js.map +1 -1
- package/dist/store/native-state-handler.d.ts +44 -0
- package/dist/store/native-state-handler.js +62 -0
- package/dist/store/native-state-handler.js.map +1 -0
- package/dist/store/observable-state-handler.d.ts +34 -0
- package/dist/store/observable-state-handler.js +45 -1
- package/dist/store/observable-state-handler.js.map +1 -1
- package/dist/store/signal-state-handler.d.ts +26 -0
- package/dist/store/signal-state-handler.js +35 -0
- package/dist/store/signal-state-handler.js.map +1 -1
- package/dist/store/state-singleton.d.ts +14 -0
- package/dist/store/state-singleton.js +20 -1
- package/dist/store/state-singleton.js.map +1 -1
- package/dist/types/types.d.ts +9 -0
- package/dist/types/types.js +3 -0
- package/dist/types/types.js.map +1 -1
- package/dist/utils/selector-cache.d.ts +17 -0
- package/dist/utils/selector-cache.js +28 -1
- package/dist/utils/selector-cache.js.map +1 -1
- package/package.json +12 -1
- package/src/config/status-quo-config.ts +64 -1
- package/src/index.ts +29 -0
- package/src/react/hooks/__tests__/state-provider.spec.tsx +2 -2
- package/src/react/hooks/index.ts +13 -8
- package/src/react/hooks/state-actions.tsx +23 -2
- package/src/react/hooks/state-factory.tsx +34 -0
- package/src/react/hooks/state-handler.tsx +15 -0
- package/src/react/hooks/state-provider.tsx +36 -40
- package/src/react/hooks/state-singleton.tsx +37 -7
- package/src/react/hooks/state-subscription-selector.tsx +85 -7
- package/src/react/hooks/state-subscription.tsx +75 -0
- package/src/react/index.ts +16 -1
- package/src/store/__tests__/native-state-handler.spec.ts +291 -0
- package/src/store/__tests__/observable-state-handler.spec.ts +8 -0
- package/src/store/base-state-handler.ts +89 -12
- package/src/store/dev-tools.ts +72 -27
- package/src/store/index.ts +16 -0
- package/src/store/native-state-handler.ts +98 -0
- package/src/store/observable-state-handler.ts +57 -0
- package/src/store/signal-state-handler.ts +47 -1
- package/src/store/state-singleton.ts +30 -0
- package/src/types/types.ts +16 -0
- package/src/utils/selector-cache.ts +37 -0
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,15 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @veams/status-quo@1.7.0 test
|
|
4
|
+
> cross-env NODE_ENV=test jest --config jest.config.cjs
|
|
5
|
+
|
|
6
|
+
[1m[2mDetermining test suites to run...[22m[22m[?2026h[999D[K
|
|
7
|
+
|
|
8
|
+
[1mTest Suites: [22m0 of 6 total
|
|
9
|
+
[1mTests: [22m0 total
|
|
10
|
+
[1mSnapshots: [22m0 total
|
|
11
|
+
[1mTime:[22m 0 s, estimated 2 s[?2026l[?2026h
|
|
12
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-singleton.spec.tsx[22m
|
|
13
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-selector.spec.tsx[22m
|
|
14
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1mnative-state-handler.spec.ts[22m
|
|
15
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-provider.spec.tsx[22m
|
|
16
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1mobservable-state-handler.spec.ts[22m
|
|
17
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1msignal-state-handler.spec.ts[22m
|
|
18
|
+
|
|
19
|
+
[1mTest Suites: [22m0 of 6 total
|
|
20
|
+
[1mTests: [22m0 total
|
|
21
|
+
[1mSnapshots: [22m0 total
|
|
22
|
+
[1mTime:[22m 0 s, estimated 2 s[?2026l[?2026h
|
|
23
|
+
|
|
24
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-singleton.spec.tsx[22m
|
|
25
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-selector.spec.tsx[22m
|
|
26
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1mnative-state-handler.spec.ts[22m
|
|
27
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-provider.spec.tsx[22m
|
|
28
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1mobservable-state-handler.spec.ts[22m
|
|
29
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1msignal-state-handler.spec.ts[22m
|
|
30
|
+
|
|
31
|
+
[1mTest Suites: [22m0 of 6 total
|
|
32
|
+
[1mTests: [22m0 total
|
|
33
|
+
[1mSnapshots: [22m0 total
|
|
34
|
+
[1mTime:[22m 0 s, estimated 2 s[?2026l[?2026h
|
|
35
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-singleton.spec.tsx[22m
|
|
36
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-selector.spec.tsx[22m
|
|
37
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1mnative-state-handler.spec.ts[22m
|
|
38
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-provider.spec.tsx[22m
|
|
39
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1mobservable-state-handler.spec.ts[22m
|
|
40
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1msignal-state-handler.spec.ts[22m
|
|
41
|
+
|
|
42
|
+
[1mTest Suites: [22m0 of 6 total
|
|
43
|
+
[1mTests: [22m0 total
|
|
44
|
+
[1mSnapshots: [22m0 total
|
|
45
|
+
[1mTime:[22m 0 s, estimated 2 s[?2026l[?2026h
|
|
46
|
+
|
|
47
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-singleton.spec.tsx[22m
|
|
48
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-selector.spec.tsx[22m
|
|
49
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1mnative-state-handler.spec.ts[22m
|
|
50
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-provider.spec.tsx[22m
|
|
51
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1mobservable-state-handler.spec.ts[22m
|
|
52
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1msignal-state-handler.spec.ts[22m
|
|
53
|
+
|
|
54
|
+
[1mTest Suites: [22m0 of 6 total
|
|
55
|
+
[1mTests: [22m0 total
|
|
56
|
+
[1mSnapshots: [22m0 total
|
|
57
|
+
[1mTime:[22m 0 s, estimated 2 s[?2026l[?2026h
|
|
58
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-singleton.spec.tsx[22m
|
|
59
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-selector.spec.tsx[22m
|
|
60
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-provider.spec.tsx[22m
|
|
61
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1mobservable-state-handler.spec.ts[22m
|
|
62
|
+
|
|
63
|
+
[1mTest Suites: [22m[1m[32m2 passed[39m[22m, 2 of 6 total
|
|
64
|
+
[1mTests: [22m[1m[32m19 passed[39m[22m, 19 total
|
|
65
|
+
[1mSnapshots: [22m0 total
|
|
66
|
+
[1mTime:[22m 0 s, estimated 2 s[?2026l[?2026h
|
|
67
|
+
|
|
68
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-singleton.spec.tsx[22m
|
|
69
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-selector.spec.tsx[22m
|
|
70
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-provider.spec.tsx[22m
|
|
71
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1mobservable-state-handler.spec.ts[22m
|
|
72
|
+
|
|
73
|
+
[1mTest Suites: [22m[1m[32m2 passed[39m[22m, 2 of 6 total
|
|
74
|
+
[1mTests: [22m[1m[32m19 passed[39m[22m, 19 total
|
|
75
|
+
[1mSnapshots: [22m0 total
|
|
76
|
+
[1mTime:[22m 0 s, estimated 2 s[?2026l[?2026h
|
|
77
|
+
|
|
78
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-singleton.spec.tsx[22m
|
|
79
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-selector.spec.tsx[22m
|
|
80
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-provider.spec.tsx[22m
|
|
81
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1mobservable-state-handler.spec.ts[22m
|
|
82
|
+
|
|
83
|
+
[1mTest Suites: [22m[1m[32m2 passed[39m[22m, 2 of 6 total
|
|
84
|
+
[1mTests: [22m[1m[32m19 passed[39m[22m, 19 total
|
|
85
|
+
[1mSnapshots: [22m0 total
|
|
86
|
+
[1mTime:[22m 0 s, estimated 2 s[?2026l[?2026h
|
|
87
|
+
|
|
88
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-singleton.spec.tsx[22m
|
|
89
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-selector.spec.tsx[22m
|
|
90
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-provider.spec.tsx[22m
|
|
91
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/store/__tests__/[22m[1mobservable-state-handler.spec.ts[22m
|
|
92
|
+
|
|
93
|
+
[1mTest Suites: [22m[1m[32m2 passed[39m[22m, 2 of 6 total
|
|
94
|
+
[1mTests: [22m[1m[32m19 passed[39m[22m, 19 total
|
|
95
|
+
[1mSnapshots: [22m0 total
|
|
96
|
+
[1mTime:[22m 0 s, estimated 2 s[?2026l[?2026h
|
|
97
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-provider.spec.tsx[22m
|
|
98
|
+
|
|
99
|
+
[1mTest Suites: [22m[1m[32m5 passed[39m[22m, 5 of 6 total
|
|
100
|
+
[1mTests: [22m[1m[32m49 passed[39m[22m, 49 total
|
|
101
|
+
[1mSnapshots: [22m0 total
|
|
102
|
+
[1mTime:[22m 1 s, estimated 2 s[?2026l[?2026h
|
|
103
|
+
|
|
104
|
+
[0m[7m[33m[1m RUNS [22m[39m[27m[0m [2msrc/react/hooks/__tests__/[22m[1mstate-provider.spec.tsx[22m
|
|
105
|
+
|
|
106
|
+
[1mTest Suites: [22m[1m[32m5 passed[39m[22m, 5 of 6 total
|
|
107
|
+
[1mTests: [22m[1m[32m49 passed[39m[22m, 49 total
|
|
108
|
+
[1mSnapshots: [22m0 total
|
|
109
|
+
[1mTime:[22m 1 s, estimated 2 s[?2026l[?2026h
|
|
110
|
+
[1mTest Suites: [22m[1m[32m6 passed[39m[22m, 6 total
|
|
111
|
+
[1mTests: [22m[1m[32m50 passed[39m[22m, 50 total
|
|
112
|
+
[1mSnapshots: [22m0 total
|
|
113
|
+
[1mTime:[22m 1.152 s, estimated 2 s
|
|
114
|
+
[2mRan all test suites[22m[2m.[22m
|
|
115
|
+
[?2026h[?2026l⠙[1G[0K
|
package/CHANGELOG.md
CHANGED
|
@@ -7,11 +7,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
9
|
### Added
|
|
10
|
+
- `NativeStateHandler` for zero-dependency state management using plain JavaScript.
|
|
10
11
|
- `StateProvider` for sharing one handler instance across a scoped React subtree.
|
|
11
12
|
- `useProvidedStateHandler()`, `useProvidedStateActions()`, and `useProvidedStateSubscription()` for provider-scoped composition.
|
|
12
13
|
- `setupStatusQuo({ devTools: { enabled } })` for global Redux DevTools defaults.
|
|
13
14
|
|
|
14
15
|
### Changed
|
|
16
|
+
- The library is now **zero-dependency** when only `NativeStateHandler` is used (`rxjs` and `@preact/signals-core` are peer dependencies).
|
|
15
17
|
- React-specific exports now live under `@veams/status-quo/react`.
|
|
16
18
|
- `options.devTools.namespace` is now optional and falls back to the handler class name.
|
|
17
19
|
- `ObservableStateHandler#getObservable(options?)` is now the canonical API for the full state stream.
|
package/README.md
CHANGED
|
@@ -28,7 +28,9 @@ This README summarizes the package API. The full routed documentation lives in V
|
|
|
28
28
|
|
|
29
29
|
## Overview
|
|
30
30
|
|
|
31
|
-
StatusQuo is a small, framework-agnostic state layer that focuses on explicit lifecycle, clear action APIs, and a minimal subscription surface. It ships
|
|
31
|
+
StatusQuo is a small, framework-agnostic state layer that focuses on explicit lifecycle, clear action APIs, and a minimal subscription surface. It ships three handler implementations with the same public interface: **Native** (zero-dependency), **RxJS-backed** (observables), and **Signals-backed** (stores).
|
|
32
|
+
|
|
33
|
+
When using the `NativeStateHandler`, the library is **completely zero-dependency**.
|
|
32
34
|
|
|
33
35
|
## Philosophy
|
|
34
36
|
|
|
@@ -47,13 +49,17 @@ Live docs:
|
|
|
47
49
|
Install:
|
|
48
50
|
|
|
49
51
|
```bash
|
|
50
|
-
|
|
52
|
+
# Minimal installation (Native only)
|
|
53
|
+
npm install @veams/status-quo
|
|
54
|
+
|
|
55
|
+
# Optional engines
|
|
56
|
+
npm install rxjs @preact/signals-core
|
|
51
57
|
```
|
|
52
58
|
|
|
53
59
|
Create a store and use it in a component:
|
|
54
60
|
|
|
55
61
|
```ts
|
|
56
|
-
import {
|
|
62
|
+
import { NativeStateHandler } from '@veams/status-quo';
|
|
57
63
|
import { useStateFactory } from '@veams/status-quo/react';
|
|
58
64
|
|
|
59
65
|
type CounterState = { count: number };
|
|
@@ -63,7 +69,7 @@ type CounterActions = {
|
|
|
63
69
|
decrease: () => void;
|
|
64
70
|
};
|
|
65
71
|
|
|
66
|
-
class CounterStore extends
|
|
72
|
+
class CounterStore extends NativeStateHandler<CounterState, CounterActions> {
|
|
67
73
|
constructor() {
|
|
68
74
|
super({ initialState: { count: 0 } });
|
|
69
75
|
}
|
|
@@ -97,12 +103,13 @@ setupStatusQuo({
|
|
|
97
103
|
|
|
98
104
|
## Handlers
|
|
99
105
|
|
|
100
|
-
StatusQuo provides
|
|
106
|
+
StatusQuo provides three handler implementations with the same public interface:
|
|
101
107
|
|
|
108
|
+
- `NativeStateHandler` (**Zero dependency**, plain JS)
|
|
102
109
|
- `ObservableStateHandler` (RxJS-backed)
|
|
103
110
|
- `SignalStateHandler` (Signals-backed)
|
|
104
111
|
|
|
105
|
-
|
|
112
|
+
All are built on `BaseStateHandler`, which provides the shared lifecycle and devtools support.
|
|
106
113
|
|
|
107
114
|
## Hooks
|
|
108
115
|
|
|
@@ -489,7 +496,7 @@ const [name] = useStateSingleton(UserSingleton, (state) => state.user.name);
|
|
|
489
496
|
|
|
490
497
|
## Devtools
|
|
491
498
|
|
|
492
|
-
Status Quo supports the Redux DevTools browser extension on
|
|
499
|
+
Status Quo supports the Redux DevTools browser extension on `NativeStateHandler`, `ObservableStateHandler`, and `SignalStateHandler`.
|
|
493
500
|
|
|
494
501
|
Turn it on globally:
|
|
495
502
|
|
|
@@ -587,6 +594,43 @@ Protected helpers:
|
|
|
587
594
|
- If `selector` is omitted, identity selection is used.
|
|
588
595
|
- `onChange` is only called when selected value changes according to `isEqual` (default `Object.is`).
|
|
589
596
|
|
|
597
|
+
### `NativeStateHandler<S, A>`
|
|
598
|
+
|
|
599
|
+
**Zero-dependency**, plain JS handler. Extends `BaseStateHandler`.
|
|
600
|
+
|
|
601
|
+
Constructor:
|
|
602
|
+
|
|
603
|
+
```ts
|
|
604
|
+
protected constructor({
|
|
605
|
+
initialState,
|
|
606
|
+
options
|
|
607
|
+
}: {
|
|
608
|
+
initialState: S;
|
|
609
|
+
options?: {
|
|
610
|
+
devTools?: { enabled?: boolean; namespace?: string };
|
|
611
|
+
distinct?: {
|
|
612
|
+
enabled?: boolean;
|
|
613
|
+
comparator?: (previous: S, next: S) => boolean;
|
|
614
|
+
};
|
|
615
|
+
useDistinctUntilChanged?: boolean;
|
|
616
|
+
};
|
|
617
|
+
})
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
Public methods:
|
|
621
|
+
|
|
622
|
+
- `subscribe(listener: () => void): () => void`
|
|
623
|
+
- `subscribe(listener: (value: S) => void): () => void`
|
|
624
|
+
|
|
625
|
+
Notes:
|
|
626
|
+
- The handler uses plain JS and a `Set` for listener management.
|
|
627
|
+
- Zero external dependencies.
|
|
628
|
+
- Distinct behavior defaults to enabled.
|
|
629
|
+
- Configure it globally via `setupStatusQuo` or per handler via `options.distinct`.
|
|
630
|
+
- Devtools can be enabled globally via `setupStatusQuo({ devTools: { enabled: true } })` or overridden per handler via `options.devTools`.
|
|
631
|
+
- `subscribe` fires immediately with the current snapshot and then on subsequent changes.
|
|
632
|
+
- Subscribers receive the next state snapshot as a callback argument.
|
|
633
|
+
|
|
590
634
|
### `ObservableStateHandler<S, A>`
|
|
591
635
|
|
|
592
636
|
RxJS-backed handler. Extends `BaseStateHandler`.
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global configuration and utility functions for Status Quo state management.
|
|
3
|
+
*/
|
|
1
4
|
export type DistinctComparator<T = unknown> = (previous: T, next: T) => boolean;
|
|
2
5
|
export type DistinctOptions<T = unknown> = {
|
|
3
6
|
enabled?: boolean;
|
|
@@ -25,10 +28,28 @@ type ResolvedStatusQuoConfig = {
|
|
|
25
28
|
devTools: ResolvedDevToolsOptions;
|
|
26
29
|
distinct: ResolvedDistinctOptions;
|
|
27
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Global setup function to configure Status Quo.
|
|
33
|
+
*/
|
|
28
34
|
export declare function setupStatusQuo<T = unknown>(config?: StatusQuoConfig<T>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Resolves the final distinct options for a specific state handler.
|
|
37
|
+
* Combines global configuration with handler-specific overrides.
|
|
38
|
+
*/
|
|
29
39
|
export declare function resolveDistinctOptions<T>(options?: DistinctOptions<T>, useDistinctUntilChanged?: boolean): ResolvedDistinctOptions<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Resolves the final DevTools options for a specific state handler.
|
|
42
|
+
* Combines global configuration with handler-specific overrides.
|
|
43
|
+
*/
|
|
30
44
|
export declare function resolveDevToolsOptions(options?: DevToolsOptions): ResolvedDevToolsOptions;
|
|
45
|
+
/**
|
|
46
|
+
* Returns a copy of the current global configuration.
|
|
47
|
+
*/
|
|
31
48
|
export declare function getStatusQuoConfig(): ResolvedStatusQuoConfig;
|
|
32
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Resets the Status Quo configuration to its default values.
|
|
51
|
+
* Useful for ensuring test isolation in unit tests.
|
|
52
|
+
* @internal testing helper
|
|
53
|
+
*/
|
|
33
54
|
export declare function resetStatusQuoForTests(): void;
|
|
34
55
|
export {};
|
|
@@ -1,49 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global configuration and utility functions for Status Quo state management.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Default comparator function that uses referential equality (Object.is)
|
|
6
|
+
* and falls back to JSON stringification for structural equality.
|
|
7
|
+
*/
|
|
1
8
|
function distinctAsJson(previous, next) {
|
|
9
|
+
// Fast path for referential equality.
|
|
2
10
|
if (Object.is(previous, next)) {
|
|
3
11
|
return true;
|
|
4
12
|
}
|
|
13
|
+
// Structural comparison using JSON stringification as a fallback.
|
|
5
14
|
try {
|
|
6
15
|
return JSON.stringify(previous) === JSON.stringify(next);
|
|
7
16
|
}
|
|
8
17
|
catch {
|
|
18
|
+
// If stringification fails, assume they are not equal.
|
|
9
19
|
return false;
|
|
10
20
|
}
|
|
11
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates the default Status Quo configuration.
|
|
24
|
+
*/
|
|
12
25
|
function createDefaultStatusQuoConfig() {
|
|
13
26
|
return {
|
|
27
|
+
// DevTools integration is disabled by default.
|
|
14
28
|
devTools: {
|
|
15
29
|
enabled: false,
|
|
16
30
|
},
|
|
31
|
+
// Distinct emission is enabled by default with JSON-based structural equality.
|
|
17
32
|
distinct: {
|
|
18
33
|
enabled: true,
|
|
19
34
|
comparator: distinctAsJson,
|
|
20
35
|
},
|
|
21
36
|
};
|
|
22
37
|
}
|
|
38
|
+
// Global configuration instance, initialized with defaults.
|
|
23
39
|
let statusQuoConfig = createDefaultStatusQuoConfig();
|
|
40
|
+
/**
|
|
41
|
+
* Global setup function to configure Status Quo.
|
|
42
|
+
*/
|
|
24
43
|
export function setupStatusQuo(config = {}) {
|
|
44
|
+
// Merge the provided configuration with the current global config.
|
|
25
45
|
statusQuoConfig = {
|
|
46
|
+
// Update global DevTools status.
|
|
26
47
|
devTools: {
|
|
27
48
|
enabled: config.devTools?.enabled ?? false,
|
|
28
49
|
},
|
|
50
|
+
// Update global distinct emission status and comparator.
|
|
29
51
|
distinct: {
|
|
30
52
|
enabled: config.distinct?.enabled ?? true,
|
|
31
53
|
comparator: (config.distinct?.comparator ?? distinctAsJson),
|
|
32
54
|
},
|
|
33
55
|
};
|
|
34
56
|
}
|
|
35
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Resolves the final distinct options for a specific state handler.
|
|
59
|
+
* Combines global configuration with handler-specific overrides.
|
|
60
|
+
*/
|
|
61
|
+
export function resolveDistinctOptions(
|
|
62
|
+
// Handler-specific distinct options.
|
|
63
|
+
options,
|
|
64
|
+
// Boolean flag often used to override or determine enabled status.
|
|
65
|
+
useDistinctUntilChanged) {
|
|
36
66
|
return {
|
|
67
|
+
// Determine the enabled status for distinct emissions.
|
|
37
68
|
enabled: options?.enabled ?? useDistinctUntilChanged ?? statusQuoConfig.distinct.enabled,
|
|
69
|
+
// Determine the comparator function to use.
|
|
38
70
|
comparator: (options?.comparator ??
|
|
39
71
|
statusQuoConfig.distinct.comparator),
|
|
40
72
|
};
|
|
41
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Resolves the final DevTools options for a specific state handler.
|
|
76
|
+
* Combines global configuration with handler-specific overrides.
|
|
77
|
+
*/
|
|
42
78
|
export function resolveDevToolsOptions(options) {
|
|
43
79
|
return {
|
|
80
|
+
// Determine the enabled status for DevTools integration.
|
|
44
81
|
enabled: options?.enabled ?? statusQuoConfig.devTools.enabled,
|
|
45
82
|
};
|
|
46
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns a copy of the current global configuration.
|
|
86
|
+
*/
|
|
47
87
|
export function getStatusQuoConfig() {
|
|
48
88
|
return {
|
|
49
89
|
devTools: {
|
|
@@ -55,7 +95,11 @@ export function getStatusQuoConfig() {
|
|
|
55
95
|
},
|
|
56
96
|
};
|
|
57
97
|
}
|
|
58
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Resets the Status Quo configuration to its default values.
|
|
100
|
+
* Useful for ensuring test isolation in unit tests.
|
|
101
|
+
* @internal testing helper
|
|
102
|
+
*/
|
|
59
103
|
export function resetStatusQuoForTests() {
|
|
60
104
|
statusQuoConfig = createDefaultStatusQuoConfig();
|
|
61
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-quo-config.js","sourceRoot":"","sources":["../../src/config/status-quo-config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"status-quo-config.js","sourceRoot":"","sources":["../../src/config/status-quo-config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAyDH;;;GAGG;AACH,SAAS,cAAc,CAAC,QAAiB,EAAE,IAAa;IACtD,sCAAsC;IACtC,IAAI,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kEAAkE;IAClE,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,uDAAuD;QACvD,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,4BAA4B;IACnC,OAAO;QACL,+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OAAO;SAC1C;QACD,QAAQ,EAAE;YACR,OAAO,EAAE,eAAe,CAAC,QAAQ,CAAC,OAAO;YACzC,UAAU,EAAE,eAAe,CAAC,QAAQ,CAAC,UAAU;SAChD;KACyB,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB;IACpC,eAAe,GAAG,4BAA4B,EAAE,CAAC;AACnD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main entry point for the Status Quo state management library.
|
|
3
|
+
* Exports core functionality for both store and React integration.
|
|
4
|
+
*/
|
|
1
5
|
import { setupStatusQuo } from './config/status-quo-config.js';
|
|
2
|
-
import { BaseStateHandler, makeStateSingleton, ObservableStateHandler, SignalStateHandler } from './store';
|
|
6
|
+
import { BaseStateHandler, makeStateSingleton, NativeStateHandler, ObservableStateHandler, SignalStateHandler } from './store';
|
|
3
7
|
import type { DevToolsOptions, GlobalDevToolsOptions, DistinctComparator, DistinctOptions, StatusQuoConfig } from './config/status-quo-config.js';
|
|
4
8
|
import type { StateSingleton, StateSingletonOptions } from './store';
|
|
5
9
|
import type { StateSubscriptionHandler } from './types/types.js';
|
|
6
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Core state management functions and classes.
|
|
12
|
+
*/
|
|
13
|
+
export { BaseStateHandler, makeStateSingleton, NativeStateHandler, ObservableStateHandler, setupStatusQuo, SignalStateHandler, };
|
|
14
|
+
/**
|
|
15
|
+
* Type definitions for public API.
|
|
16
|
+
*/
|
|
7
17
|
export type { DevToolsOptions, GlobalDevToolsOptions, DistinctComparator, DistinctOptions, StateSingleton, StateSingletonOptions, StateSubscriptionHandler, StatusQuoConfig, };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main entry point for the Status Quo state management library.
|
|
3
|
+
* Exports core functionality for both store and React integration.
|
|
4
|
+
*/
|
|
5
|
+
// Import internal setup functions and core state handlers.
|
|
1
6
|
import { setupStatusQuo } from './config/status-quo-config.js';
|
|
2
|
-
import { BaseStateHandler, makeStateSingleton, ObservableStateHandler, SignalStateHandler, } from './store';
|
|
3
|
-
|
|
7
|
+
import { BaseStateHandler, makeStateSingleton, NativeStateHandler, ObservableStateHandler, SignalStateHandler, } from './store';
|
|
8
|
+
/**
|
|
9
|
+
* Core state management functions and classes.
|
|
10
|
+
*/
|
|
11
|
+
export {
|
|
12
|
+
// Abstract base class for all state handlers.
|
|
13
|
+
BaseStateHandler,
|
|
14
|
+
// Factory function for creating singleton state handlers.
|
|
15
|
+
makeStateSingleton,
|
|
16
|
+
// Lightweight state handler using plain JavaScript.
|
|
17
|
+
NativeStateHandler,
|
|
18
|
+
// State handler powered by RxJS BehaviorSubjects.
|
|
19
|
+
ObservableStateHandler,
|
|
20
|
+
// Global configuration function for Status Quo.
|
|
21
|
+
setupStatusQuo,
|
|
22
|
+
// State handler powered by Preact Signals.
|
|
23
|
+
SignalStateHandler, };
|
|
4
24
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,2DAA2D;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,SAAS,CAAC;AAajB;;GAEG;AACH,OAAO;AACL,8CAA8C;AAC9C,gBAAgB;AAChB,0DAA0D;AAC1D,kBAAkB;AAClB,oDAAoD;AACpD,kBAAkB;AAClB,kDAAkD;AAClD,sBAAsB;AACtB,gDAAgD;AAChD,cAAc;AACd,2CAA2C;AAC3C,kBAAkB,GACnB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { act } from 'react';
|
|
2
2
|
import { createRoot } from 'react-dom/client';
|
|
3
|
-
import { StateProvider, useProvidedStateActions, useProvidedStateHandler, useProvidedStateSubscription, } from '../
|
|
3
|
+
import { StateProvider, useProvidedStateActions, useProvidedStateHandler, useProvidedStateSubscription, } from '../index.js';
|
|
4
4
|
class TestStateHandler {
|
|
5
5
|
initialState;
|
|
6
6
|
state;
|
|
@@ -172,7 +172,7 @@ describe('StateProvider', () => {
|
|
|
172
172
|
act(() => {
|
|
173
173
|
root.render(React.createElement(MissingProviderConsumer, null));
|
|
174
174
|
});
|
|
175
|
-
}).toThrow('
|
|
175
|
+
}).toThrow('useProvidedStateHandler must be used within a StateProvider');
|
|
176
176
|
consoleErrorSpy.mockRestore();
|
|
177
177
|
});
|
|
178
178
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-provider.spec.js","sourceRoot":"","sources":["../../../../src/react/hooks/__tests__/state-provider.spec.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,
|
|
1
|
+
{"version":3,"file":"state-provider.spec.js","sourceRoot":"","sources":["../../../../src/react/hooks/__tests__/state-provider.spec.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EACL,aA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IAAC,QAAQ,EAAE,SAAS,GAAI,CACxB,CACjB,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,GAAG,EAAE;YACP,IAAI,CAAC,MAAM,CACT,oBAAC,aAAa,IAAC,QAAQ,EAAE,aAAa;gBACpC,oBAAC,aAAa,IAAC,QAAQ,EAAE,SAAS,GAAI,CACxB,CACjB,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC3C,MAAM,CAAC,SAAS,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAChD,MAAM,CAAC,SAAS,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;QACzE,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAEzF,MAAM,CAAC,GAAG,EAAE;YACV,GAAG,CAAC,GAAG,EAAE;gBACP,IAAI,CAAC,MAAM,CAAC,oBAAC,uBAAuB,OAAG,CAAC,CAAC;YAC3C,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC,OAAO,CAAC,6DAA6D,CAAC,CAAC;QAE1E,eAAe,CAAC,WAAW,EAAE,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Export available hooks for React components.
|
|
3
|
+
*/
|
|
4
|
+
export { useProvidedStateActions, useStateActions } from './state-actions.js';
|
|
2
5
|
export { useStateFactory } from './state-factory.js';
|
|
3
6
|
export { useStateHandler } from './state-handler.js';
|
|
4
|
-
export { StateProvider,
|
|
7
|
+
export { StateProvider, useProvidedStateHandler } from './state-provider.js';
|
|
5
8
|
export { useStateSingleton } from './state-singleton.js';
|
|
6
|
-
export { useStateSubscription } from './state-subscription.js';
|
|
9
|
+
export { useProvidedStateSubscription, useStateSubscription } from './state-subscription.js';
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Export available hooks for React components.
|
|
3
|
+
*/
|
|
4
|
+
// Export hook to access the actions of a state handler.
|
|
5
|
+
export { useProvidedStateActions, useStateActions } from './state-actions.js';
|
|
6
|
+
// Export hook to create and manage a state handler within a component.
|
|
2
7
|
export { useStateFactory } from './state-factory.js';
|
|
8
|
+
// Export hook to manage a state handler's lifecycle within a component's reference.
|
|
3
9
|
export { useStateHandler } from './state-handler.js';
|
|
4
|
-
|
|
10
|
+
// Export hook and component to use a state handler through React Context.
|
|
11
|
+
export { StateProvider, useProvidedStateHandler } from './state-provider.js';
|
|
12
|
+
// Export hook to use a singleton state handler.
|
|
5
13
|
export { useStateSingleton } from './state-singleton.js';
|
|
6
|
-
|
|
14
|
+
// Export hook to subscribe to a state handler and receive its state updates.
|
|
15
|
+
export { useProvidedStateSubscription, useStateSubscription } from './state-subscription.js';
|
|
7
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wDAAwD;AACxD,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC9E,uEAAuE;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,oFAAoF;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,0EAA0E;AAC1E,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC7E,gDAAgD;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,6EAA6E;AAC7E,OAAO,EAAE,4BAA4B,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import type { StateSubscriptionHandler } from '../../types/types.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Returns the actions of a state handler instance.
|
|
4
|
+
* memoized based on the state handler instance itself.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useStateActions<V, A>(stateHandler: StateSubscriptionHandler<V, A>): A;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the actions of the state handler provided by the nearest StateProvider.
|
|
9
|
+
*/
|
|
10
|
+
export declare function useProvidedStateActions<V, A>(): A;
|
|
@@ -1,5 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility hook for accessing actions from a state handler instance.
|
|
3
|
+
*/
|
|
1
4
|
import { useMemo } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
5
|
+
import { useProvidedStateHandler } from './state-provider.js';
|
|
6
|
+
/**
|
|
7
|
+
* Returns the actions of a state handler instance.
|
|
8
|
+
* memoized based on the state handler instance itself.
|
|
9
|
+
*/
|
|
10
|
+
export function useStateActions(stateHandler) {
|
|
11
|
+
// Access and memoize the actions from the state handler.
|
|
12
|
+
// This ensures the action object remains referentially stable as long as the state handler is the same.
|
|
13
|
+
const actions = useMemo(() => stateHandler.getActions(), [stateHandler]);
|
|
14
|
+
// Return the set of actions.
|
|
15
|
+
return actions;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns the actions of the state handler provided by the nearest StateProvider.
|
|
19
|
+
*/
|
|
20
|
+
export function useProvidedStateActions() {
|
|
21
|
+
const stateHandler = useProvidedStateHandler();
|
|
22
|
+
return useStateActions(stateHandler);
|
|
4
23
|
}
|
|
5
24
|
//# sourceMappingURL=state-actions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-actions.js","sourceRoot":"","sources":["../../../src/react/hooks/state-actions.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"state-actions.js","sourceRoot":"","sources":["../../../src/react/hooks/state-actions.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGhC,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAO,YAA4C;IAChF,yDAAyD;IACzD,wGAAwG;IACxG,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;IAEzE,6BAA6B;IAC7B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,MAAM,YAAY,GAAG,uBAAuB,EAAQ,CAAC;IACrD,OAAO,eAAe,CAAC,YAAY,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import type { StateSubscriptionHandler } from '../../types/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Type signatures for selector and equality functions.
|
|
4
|
+
*/
|
|
2
5
|
type StateSelector<State, SelectedState> = (state: State) => SelectedState;
|
|
3
6
|
type EqualityFn<SelectedState> = (current: SelectedState, next: SelectedState) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Factory hook to create and subscribe to a state handler.
|
|
9
|
+
* Manages the handler instance using useStateHandler and its subscription with useStateSubscription.
|
|
10
|
+
*/
|
|
4
11
|
export declare function useStateFactory<V, A, P extends unknown[]>(stateFactoryFunction: (...args: P) => StateSubscriptionHandler<V, A>, params?: P): [V, A];
|
|
5
12
|
export declare function useStateFactory<V, A, P extends unknown[], Sel>(stateFactoryFunction: (...args: P) => StateSubscriptionHandler<V, A>, selector: StateSelector<V, Sel>, params?: P): [Sel, A];
|
|
6
13
|
export declare function useStateFactory<V, A, P extends unknown[], Sel>(stateFactoryFunction: (...args: P) => StateSubscriptionHandler<V, A>, selector: StateSelector<V, Sel>, isEqual?: EqualityFn<Sel>, params?: P): [Sel, A];
|