stunk 2.3.0 → 2.4.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 (47) hide show
  1. package/dist/{core/core.d.ts → core-C7jFiHdO.d.ts} +5 -9
  2. package/dist/index.cjs +2 -1
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +171 -0
  5. package/dist/index.d.ts +171 -7
  6. package/dist/index.js +2 -6
  7. package/dist/index.js.map +1 -0
  8. package/dist/middleware/index.d.ts +45 -4
  9. package/dist/middleware/index.js +2 -6
  10. package/dist/middleware/index.js.map +1 -0
  11. package/dist/use-react/index.d.ts +82 -7
  12. package/dist/use-react/index.js +2 -7
  13. package/dist/use-react/index.js.map +1 -0
  14. package/package.json +25 -21
  15. package/dist/core/asyncChunk.d.ts +0 -28
  16. package/dist/core/asyncChunk.js +0 -50
  17. package/dist/core/computed.d.ts +0 -15
  18. package/dist/core/computed.js +0 -58
  19. package/dist/core/core.js +0 -102
  20. package/dist/core/selector.d.ts +0 -17
  21. package/dist/core/selector.js +0 -45
  22. package/dist/core/types.d.ts +0 -16
  23. package/dist/core/types.js +0 -1
  24. package/dist/middleware/history.d.ts +0 -30
  25. package/dist/middleware/history.js +0 -68
  26. package/dist/middleware/logger.d.ts +0 -2
  27. package/dist/middleware/logger.js +0 -4
  28. package/dist/middleware/persistence.d.ts +0 -8
  29. package/dist/middleware/persistence.js +0 -25
  30. package/dist/middleware/validator.d.ts +0 -2
  31. package/dist/middleware/validator.js +0 -6
  32. package/dist/use-react/hooks/useAsyncChunk.d.ts +0 -14
  33. package/dist/use-react/hooks/useAsyncChunk.js +0 -27
  34. package/dist/use-react/hooks/useChunk.d.ts +0 -6
  35. package/dist/use-react/hooks/useChunk.js +0 -26
  36. package/dist/use-react/hooks/useChunkProperty.d.ts +0 -6
  37. package/dist/use-react/hooks/useChunkProperty.js +0 -10
  38. package/dist/use-react/hooks/useChunkValue.d.ts +0 -6
  39. package/dist/use-react/hooks/useChunkValue.js +0 -9
  40. package/dist/use-react/hooks/useChunkValues.d.ts +0 -8
  41. package/dist/use-react/hooks/useChunkValues.js +0 -25
  42. package/dist/use-react/hooks/useComputed.d.ts +0 -7
  43. package/dist/use-react/hooks/useComputed.js +0 -22
  44. package/dist/use-react/hooks/useDerive.d.ts +0 -6
  45. package/dist/use-react/hooks/useDerive.js +0 -17
  46. package/dist/utils.d.ts +0 -15
  47. package/dist/utils.js +0 -113
package/dist/utils.js DELETED
@@ -1,113 +0,0 @@
1
- import { chunk } from "./core/core";
2
- export function isValidChunkValue(value) {
3
- return value !== null && value !== undefined;
4
- }
5
- export function isChunk(value) {
6
- return value &&
7
- typeof value.get === 'function' &&
8
- typeof value.set === 'function' &&
9
- typeof value.update === 'function' &&
10
- typeof value.subscribe === 'function' &&
11
- typeof value.derive === 'function' &&
12
- typeof value.reset === 'function' &&
13
- typeof value.destroy === 'function';
14
- }
15
- export function once(fn) {
16
- let called = false;
17
- let result;
18
- return () => {
19
- if (!called) {
20
- result = fn();
21
- called = true;
22
- }
23
- return result;
24
- };
25
- }
26
- ;
27
- export function combineAsyncChunks(chunks) {
28
- // Create initial state with proper typing
29
- const initialData = Object.keys(chunks).reduce((acc, key) => {
30
- acc[key] = null;
31
- return acc;
32
- }, {});
33
- const initialState = {
34
- loading: true,
35
- error: null,
36
- data: initialData
37
- };
38
- const combined = chunk(initialState);
39
- Object.entries(chunks).forEach(([key, asyncChunk]) => {
40
- asyncChunk.subscribe((state) => {
41
- const currentState = combined.get();
42
- combined.set({
43
- loading: Object.values(chunks).some(chunk => chunk.get().loading),
44
- error: Object.values(chunks)
45
- .map(chunk => chunk.get().error)
46
- .find(error => error !== null) || null,
47
- data: {
48
- ...currentState.data,
49
- [key]: state.data
50
- },
51
- });
52
- });
53
- });
54
- return combined;
55
- }
56
- export function processMiddleware(initialValue, middleware = []) {
57
- if (initialValue === null || initialValue === undefined) {
58
- throw new Error("Value cannot be null or undefined.");
59
- }
60
- let currentValue = initialValue;
61
- let index = 0;
62
- while (index < middleware.length) {
63
- const currentMiddleware = middleware[index];
64
- let nextCalled = false;
65
- let nextValue = null;
66
- currentMiddleware(currentValue, (val) => {
67
- nextCalled = true;
68
- nextValue = val;
69
- });
70
- if (!nextCalled)
71
- break;
72
- if (nextValue === null || nextValue === undefined) {
73
- throw new Error("Value cannot be null or undefined.");
74
- }
75
- currentValue = nextValue;
76
- index++;
77
- }
78
- return currentValue;
79
- }
80
- export function shallowEqual(a, b) {
81
- if (a === b) {
82
- return true;
83
- }
84
- if (!a || !b || typeof a !== typeof b) {
85
- return false;
86
- }
87
- if (Array.isArray(a) && Array.isArray(b)) {
88
- if (a.length !== b.length) {
89
- return false;
90
- }
91
- for (let i = 0; i < a.length; i++) {
92
- if (a[i] !== b[i]) {
93
- return false;
94
- }
95
- }
96
- return true;
97
- }
98
- if (typeof a === 'object' && typeof b === 'object') {
99
- const keysA = Object.keys(a);
100
- const keysB = Object.keys(b);
101
- if (keysA.length !== keysB.length) {
102
- return false;
103
- }
104
- for (const key of keysA) {
105
- if (!Object.prototype.hasOwnProperty.call(b, key) || a[key] !== b[key]) {
106
- return false;
107
- }
108
- }
109
- return true;
110
- }
111
- // For primitive types, return false. Strict equality already handled by initial check
112
- return false;
113
- }