@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.
Files changed (127) hide show
  1. package/.turbo/turbo-build.log +12 -0
  2. package/.turbo/turbo-check$colon$types.log +4 -0
  3. package/.turbo/turbo-docs$colon$build.log +14 -0
  4. package/.turbo/turbo-lint.log +8 -0
  5. package/.turbo/turbo-test.log +15 -0
  6. package/CHANGELOG.md +24 -3
  7. package/README.md +217 -41
  8. package/dist/config/status-quo-config.d.ts +13 -0
  9. package/dist/config/status-quo-config.js +14 -0
  10. package/dist/config/status-quo-config.js.map +1 -1
  11. package/dist/hooks/__tests__/state-provider.spec.d.ts +4 -0
  12. package/dist/hooks/__tests__/state-provider.spec.js +179 -0
  13. package/dist/hooks/__tests__/state-provider.spec.js.map +1 -0
  14. package/dist/hooks/__tests__/state-selector.spec.js +11 -12
  15. package/dist/hooks/__tests__/state-selector.spec.js.map +1 -1
  16. package/dist/hooks/__tests__/state-singleton.spec.js +10 -11
  17. package/dist/hooks/__tests__/state-singleton.spec.js.map +1 -1
  18. package/dist/hooks/index.d.ts +1 -0
  19. package/dist/hooks/index.js +1 -0
  20. package/dist/hooks/index.js.map +1 -1
  21. package/dist/hooks/state-factory.js.map +1 -1
  22. package/dist/hooks/state-provider.d.ts +14 -0
  23. package/dist/hooks/state-provider.js +24 -0
  24. package/dist/hooks/state-provider.js.map +1 -0
  25. package/dist/hooks/state-subscription-selector.js +6 -2
  26. package/dist/hooks/state-subscription-selector.js.map +1 -1
  27. package/dist/hooks/state-subscription.js +1 -1
  28. package/dist/hooks/state-subscription.js.map +1 -1
  29. package/dist/index.d.ts +4 -5
  30. package/dist/index.js +2 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/react/hooks/__tests__/state-provider.spec.d.ts +4 -0
  33. package/dist/react/hooks/__tests__/state-provider.spec.js +179 -0
  34. package/dist/react/hooks/__tests__/state-provider.spec.js.map +1 -0
  35. package/dist/react/hooks/__tests__/state-selector.spec.d.ts +4 -0
  36. package/dist/react/hooks/__tests__/state-selector.spec.js +547 -0
  37. package/dist/react/hooks/__tests__/state-selector.spec.js.map +1 -0
  38. package/dist/react/hooks/__tests__/state-singleton.spec.d.ts +4 -0
  39. package/dist/react/hooks/__tests__/state-singleton.spec.js +96 -0
  40. package/dist/react/hooks/__tests__/state-singleton.spec.js.map +1 -0
  41. package/{src/hooks/index.ts → dist/react/hooks/index.d.ts} +1 -0
  42. package/dist/react/hooks/index.js +7 -0
  43. package/dist/react/hooks/index.js.map +1 -0
  44. package/dist/react/hooks/state-actions.d.ts +2 -0
  45. package/dist/react/hooks/state-actions.js +5 -0
  46. package/dist/react/hooks/state-actions.js.map +1 -0
  47. package/dist/react/hooks/state-factory.d.ts +7 -0
  48. package/dist/react/hooks/state-factory.js +13 -0
  49. package/dist/react/hooks/state-factory.js.map +1 -0
  50. package/dist/react/hooks/state-handler.d.ts +2 -0
  51. package/dist/react/hooks/state-handler.js +9 -0
  52. package/dist/react/hooks/state-handler.js.map +1 -0
  53. package/dist/react/hooks/state-provider.d.ts +14 -0
  54. package/dist/react/hooks/state-provider.js +24 -0
  55. package/dist/react/hooks/state-provider.js.map +1 -0
  56. package/dist/react/hooks/state-singleton.d.ts +6 -0
  57. package/dist/react/hooks/state-singleton.js +7 -0
  58. package/dist/react/hooks/state-singleton.js.map +1 -0
  59. package/dist/react/hooks/state-subscription-selector.d.ts +3 -0
  60. package/dist/react/hooks/state-subscription-selector.js +114 -0
  61. package/dist/react/hooks/state-subscription-selector.js.map +1 -0
  62. package/dist/react/hooks/state-subscription.d.ts +9 -0
  63. package/dist/react/hooks/state-subscription.js +53 -0
  64. package/dist/react/hooks/state-subscription.js.map +1 -0
  65. package/dist/react/index.d.ts +1 -0
  66. package/dist/react/index.js +2 -0
  67. package/dist/react/index.js.map +1 -0
  68. package/dist/store/__tests__/observable-state-handler.spec.js +66 -11
  69. package/dist/store/__tests__/observable-state-handler.spec.js.map +1 -1
  70. package/dist/store/__tests__/signal-state-handler.spec.js.map +1 -1
  71. package/dist/store/base-state-handler.d.ts +3 -5
  72. package/dist/store/base-state-handler.js +10 -9
  73. package/dist/store/base-state-handler.js.map +1 -1
  74. package/dist/store/dev-tools.js +0 -3
  75. package/dist/store/dev-tools.js.map +1 -1
  76. package/dist/store/observable-state-handler.d.ts +4 -10
  77. package/dist/store/observable-state-handler.js +4 -11
  78. package/dist/store/observable-state-handler.js.map +1 -1
  79. package/dist/store/signal-state-handler.d.ts +2 -5
  80. package/dist/store/signal-state-handler.js +3 -2
  81. package/dist/store/signal-state-handler.js.map +1 -1
  82. package/dist/store/state-singleton.js +1 -1
  83. package/dist/store/state-singleton.js.map +1 -1
  84. package/eslint.config.mjs +75 -0
  85. package/package.json +18 -18
  86. package/src/config/status-quo-config.ts +31 -1
  87. package/src/index.ts +11 -15
  88. package/src/react/hooks/__tests__/state-provider.spec.tsx +286 -0
  89. package/src/{hooks → react/hooks}/__tests__/state-selector.spec.tsx +118 -44
  90. package/src/{hooks → react/hooks}/__tests__/state-singleton.spec.tsx +21 -20
  91. package/src/react/hooks/index.ts +11 -0
  92. package/src/{hooks → react/hooks}/state-actions.tsx +1 -1
  93. package/src/{hooks → react/hooks}/state-factory.tsx +2 -2
  94. package/src/{hooks → react/hooks}/state-handler.tsx +1 -1
  95. package/src/react/hooks/state-provider.tsx +56 -0
  96. package/src/{hooks → react/hooks}/state-singleton.tsx +1 -1
  97. package/src/react/hooks/state-subscription-selector.tsx +190 -0
  98. package/src/{hooks → react/hooks}/state-subscription.tsx +5 -9
  99. package/src/react/index.ts +1 -0
  100. package/src/store/__tests__/observable-state-handler.spec.ts +92 -13
  101. package/src/store/__tests__/signal-state-handler.spec.ts +5 -1
  102. package/src/store/base-state-handler.ts +17 -22
  103. package/src/store/dev-tools.ts +3 -3
  104. package/src/store/observable-state-handler.ts +12 -22
  105. package/src/store/signal-state-handler.ts +11 -8
  106. package/src/store/state-singleton.ts +1 -1
  107. package/tsconfig.json +2 -3
  108. package/.eslintrc.cjs +0 -132
  109. package/.github/workflows/pages.yml +0 -46
  110. package/.github/workflows/release.yml +0 -33
  111. package/.nvmrc +0 -1
  112. package/.prettierrc +0 -7
  113. package/docs/assets/index-BBmpszOW.css +0 -1
  114. package/docs/assets/index-Cf8El_RO.js +0 -194
  115. package/docs/assets/statusquo-logo-8GVRbxpc.png +0 -0
  116. package/docs/index.html +0 -13
  117. package/playground/index.html +0 -12
  118. package/playground/src/App.tsx +0 -699
  119. package/playground/src/assets/philosophy-agnostic.svg +0 -18
  120. package/playground/src/assets/philosophy-separation.svg +0 -13
  121. package/playground/src/assets/philosophy-swap.svg +0 -17
  122. package/playground/src/assets/statusquo-logo.png +0 -0
  123. package/playground/src/main.tsx +0 -19
  124. package/playground/src/styles.css +0 -534
  125. package/playground/tsconfig.json +0 -12
  126. package/playground/vite.config.ts +0 -18
  127. 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
- }