@veams/status-quo 1.5.1 → 1.7.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-build.log +12 -0
- package/.turbo/turbo-check$colon$types.log +4 -0
- package/.turbo/turbo-docs$colon$build.log +14 -0
- package/.turbo/turbo-lint.log +8 -0
- package/.turbo/turbo-test.log +15 -0
- package/CHANGELOG.md +24 -3
- package/README.md +217 -41
- package/dist/config/status-quo-config.d.ts +13 -0
- package/dist/config/status-quo-config.js +14 -0
- package/dist/config/status-quo-config.js.map +1 -1
- package/dist/hooks/__tests__/state-provider.spec.d.ts +4 -0
- package/dist/hooks/__tests__/state-provider.spec.js +179 -0
- package/dist/hooks/__tests__/state-provider.spec.js.map +1 -0
- package/dist/hooks/__tests__/state-selector.spec.js +11 -12
- package/dist/hooks/__tests__/state-selector.spec.js.map +1 -1
- package/dist/hooks/__tests__/state-singleton.spec.js +10 -11
- package/dist/hooks/__tests__/state-singleton.spec.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/state-factory.js.map +1 -1
- package/dist/hooks/state-provider.d.ts +14 -0
- package/dist/hooks/state-provider.js +24 -0
- package/dist/hooks/state-provider.js.map +1 -0
- package/dist/hooks/state-subscription-selector.js +6 -2
- package/dist/hooks/state-subscription-selector.js.map +1 -1
- package/dist/hooks/state-subscription.js +1 -1
- package/dist/hooks/state-subscription.js.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/react/hooks/__tests__/state-provider.spec.d.ts +4 -0
- package/dist/react/hooks/__tests__/state-provider.spec.js +179 -0
- package/dist/react/hooks/__tests__/state-provider.spec.js.map +1 -0
- package/dist/react/hooks/__tests__/state-selector.spec.d.ts +4 -0
- package/dist/react/hooks/__tests__/state-selector.spec.js +547 -0
- package/dist/react/hooks/__tests__/state-selector.spec.js.map +1 -0
- package/dist/react/hooks/__tests__/state-singleton.spec.d.ts +4 -0
- package/dist/react/hooks/__tests__/state-singleton.spec.js +96 -0
- package/dist/react/hooks/__tests__/state-singleton.spec.js.map +1 -0
- package/{src/hooks/index.ts → dist/react/hooks/index.d.ts} +1 -0
- package/dist/react/hooks/index.js +7 -0
- package/dist/react/hooks/index.js.map +1 -0
- package/dist/react/hooks/state-actions.d.ts +2 -0
- package/dist/react/hooks/state-actions.js +5 -0
- package/dist/react/hooks/state-actions.js.map +1 -0
- package/dist/react/hooks/state-factory.d.ts +7 -0
- package/dist/react/hooks/state-factory.js +13 -0
- package/dist/react/hooks/state-factory.js.map +1 -0
- package/dist/react/hooks/state-handler.d.ts +2 -0
- package/dist/react/hooks/state-handler.js +9 -0
- package/dist/react/hooks/state-handler.js.map +1 -0
- package/dist/react/hooks/state-provider.d.ts +14 -0
- package/dist/react/hooks/state-provider.js +24 -0
- package/dist/react/hooks/state-provider.js.map +1 -0
- package/dist/react/hooks/state-singleton.d.ts +6 -0
- package/dist/react/hooks/state-singleton.js +7 -0
- package/dist/react/hooks/state-singleton.js.map +1 -0
- package/dist/react/hooks/state-subscription-selector.d.ts +3 -0
- package/dist/react/hooks/state-subscription-selector.js +114 -0
- package/dist/react/hooks/state-subscription-selector.js.map +1 -0
- package/dist/react/hooks/state-subscription.d.ts +9 -0
- package/dist/react/hooks/state-subscription.js +53 -0
- package/dist/react/hooks/state-subscription.js.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +2 -0
- package/dist/react/index.js.map +1 -0
- package/dist/store/__tests__/observable-state-handler.spec.js +66 -11
- package/dist/store/__tests__/observable-state-handler.spec.js.map +1 -1
- package/dist/store/__tests__/signal-state-handler.spec.js.map +1 -1
- package/dist/store/base-state-handler.d.ts +3 -5
- package/dist/store/base-state-handler.js +10 -9
- package/dist/store/base-state-handler.js.map +1 -1
- package/dist/store/dev-tools.js +0 -3
- package/dist/store/dev-tools.js.map +1 -1
- package/dist/store/observable-state-handler.d.ts +4 -10
- package/dist/store/observable-state-handler.js +4 -11
- package/dist/store/observable-state-handler.js.map +1 -1
- package/dist/store/signal-state-handler.d.ts +2 -5
- package/dist/store/signal-state-handler.js +3 -2
- package/dist/store/signal-state-handler.js.map +1 -1
- package/dist/store/state-singleton.js +1 -1
- package/dist/store/state-singleton.js.map +1 -1
- package/eslint.config.mjs +75 -0
- package/package.json +18 -18
- package/src/config/status-quo-config.ts +31 -1
- package/src/index.ts +11 -15
- package/src/react/hooks/__tests__/state-provider.spec.tsx +286 -0
- package/src/{hooks → react/hooks}/__tests__/state-selector.spec.tsx +118 -44
- package/src/{hooks → react/hooks}/__tests__/state-singleton.spec.tsx +21 -20
- package/src/react/hooks/index.ts +11 -0
- package/src/{hooks → react/hooks}/state-actions.tsx +1 -1
- package/src/{hooks → react/hooks}/state-factory.tsx +2 -2
- package/src/{hooks → react/hooks}/state-handler.tsx +1 -1
- package/src/react/hooks/state-provider.tsx +56 -0
- package/src/{hooks → react/hooks}/state-singleton.tsx +1 -1
- package/src/react/hooks/state-subscription-selector.tsx +190 -0
- package/src/{hooks → react/hooks}/state-subscription.tsx +5 -9
- package/src/react/index.ts +1 -0
- package/src/store/__tests__/observable-state-handler.spec.ts +92 -13
- package/src/store/__tests__/signal-state-handler.spec.ts +5 -1
- package/src/store/base-state-handler.ts +17 -22
- package/src/store/dev-tools.ts +3 -3
- package/src/store/observable-state-handler.ts +12 -22
- package/src/store/signal-state-handler.ts +11 -8
- package/src/store/state-singleton.ts +1 -1
- package/tsconfig.json +2 -3
- package/.eslintrc.cjs +0 -132
- package/.github/workflows/pages.yml +0 -46
- package/.github/workflows/release.yml +0 -33
- package/.nvmrc +0 -1
- package/.prettierrc +0 -7
- package/docs/assets/index-BBmpszOW.css +0 -1
- package/docs/assets/index-Cf8El_RO.js +0 -194
- package/docs/assets/statusquo-logo-8GVRbxpc.png +0 -0
- package/docs/index.html +0 -13
- package/playground/index.html +0 -12
- package/playground/src/App.tsx +0 -699
- package/playground/src/assets/philosophy-agnostic.svg +0 -18
- package/playground/src/assets/philosophy-separation.svg +0 -13
- package/playground/src/assets/philosophy-swap.svg +0 -17
- package/playground/src/assets/statusquo-logo.png +0 -0
- package/playground/src/main.tsx +0 -19
- package/playground/src/styles.css +0 -534
- package/playground/tsconfig.json +0 -12
- package/playground/vite.config.ts +0 -18
- package/src/hooks/state-subscription-selector.tsx +0 -111
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo, useSyncExternalStore } from 'react';
|
|
2
|
-
import { createSelectorCache, selectWithCache } from '../utils/selector-cache.js';
|
|
3
|
-
|
|
4
|
-
import type { StateSubscriptionHandler } from '../types/types.js';
|
|
5
|
-
import type { EqualityFn, Selector } from '../utils/selector-cache.js';
|
|
6
|
-
|
|
7
|
-
type Listener = () => void;
|
|
8
|
-
type SharedStateSubscriptionHandler = StateSubscriptionHandler<unknown, unknown>;
|
|
9
|
-
type DeferredDestroy = {
|
|
10
|
-
refCount: number;
|
|
11
|
-
timeoutId: ReturnType<typeof setTimeout> | null;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const deferredDestroyMap = new WeakMap<SharedStateSubscriptionHandler, DeferredDestroy>();
|
|
15
|
-
|
|
16
|
-
function getDeferredDestroyState(
|
|
17
|
-
stateSubscriptionHandler: SharedStateSubscriptionHandler
|
|
18
|
-
): DeferredDestroy {
|
|
19
|
-
const existingState = deferredDestroyMap.get(stateSubscriptionHandler);
|
|
20
|
-
|
|
21
|
-
if (existingState) {
|
|
22
|
-
return existingState;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const nextState: DeferredDestroy = {
|
|
26
|
-
refCount: 0,
|
|
27
|
-
timeoutId: null,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
deferredDestroyMap.set(stateSubscriptionHandler, nextState);
|
|
31
|
-
|
|
32
|
-
return nextState;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function useStateSubscriptionSelector<V, A, Sel>(
|
|
36
|
-
stateSubscriptionHandler: StateSubscriptionHandler<V, A>,
|
|
37
|
-
selector: Selector<V, Sel>,
|
|
38
|
-
isEqual: EqualityFn<Sel> = Object.is,
|
|
39
|
-
destroyOnCleanup = true
|
|
40
|
-
) {
|
|
41
|
-
const selectorCache = useMemo(() => createSelectorCache<Sel>(), [stateSubscriptionHandler]);
|
|
42
|
-
|
|
43
|
-
const subscribe = useCallback(
|
|
44
|
-
(listener: Listener) => {
|
|
45
|
-
const sharedStateSubscriptionHandler =
|
|
46
|
-
stateSubscriptionHandler as unknown as SharedStateSubscriptionHandler;
|
|
47
|
-
const deferredDestroyState = getDeferredDestroyState(sharedStateSubscriptionHandler);
|
|
48
|
-
deferredDestroyState.refCount += 1;
|
|
49
|
-
|
|
50
|
-
if (deferredDestroyState.timeoutId) {
|
|
51
|
-
clearTimeout(deferredDestroyState.timeoutId);
|
|
52
|
-
deferredDestroyState.timeoutId = null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const unsubscribe = stateSubscriptionHandler.subscribe(listener);
|
|
56
|
-
|
|
57
|
-
return () => {
|
|
58
|
-
unsubscribe();
|
|
59
|
-
|
|
60
|
-
if (!destroyOnCleanup) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const activeDeferredDestroyState = deferredDestroyMap.get(sharedStateSubscriptionHandler);
|
|
65
|
-
|
|
66
|
-
if (!activeDeferredDestroyState) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
activeDeferredDestroyState.refCount -= 1;
|
|
71
|
-
|
|
72
|
-
if (activeDeferredDestroyState.refCount > 0) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
activeDeferredDestroyState.refCount = 0;
|
|
77
|
-
activeDeferredDestroyState.timeoutId = setTimeout(() => {
|
|
78
|
-
const pendingDeferredDestroyState = deferredDestroyMap.get(sharedStateSubscriptionHandler);
|
|
79
|
-
|
|
80
|
-
if (!pendingDeferredDestroyState || pendingDeferredDestroyState.refCount > 0) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
pendingDeferredDestroyState.timeoutId = null;
|
|
85
|
-
stateSubscriptionHandler.destroy();
|
|
86
|
-
deferredDestroyMap.delete(sharedStateSubscriptionHandler);
|
|
87
|
-
}, 0);
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
[destroyOnCleanup, stateSubscriptionHandler]
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
const selectSnapshot = useCallback(
|
|
94
|
-
(snapshot: V) => {
|
|
95
|
-
return selectWithCache(selectorCache, snapshot, selector, isEqual).value;
|
|
96
|
-
},
|
|
97
|
-
[isEqual, selector, selectorCache]
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const getSnapshot = useCallback(
|
|
101
|
-
() => selectSnapshot(stateSubscriptionHandler.getSnapshot()),
|
|
102
|
-
[selectSnapshot, stateSubscriptionHandler]
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const getServerSnapshot = useCallback(
|
|
106
|
-
() => selectSnapshot(stateSubscriptionHandler.getInitialState()),
|
|
107
|
-
[selectSnapshot, stateSubscriptionHandler]
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
111
|
-
}
|