@o/hooks 0.16.19-canary.1790165522484
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/LICENSE +21 -0
- package/README.md +120 -0
- package/dist/cjs/index.cjs +32 -0
- package/dist/cjs/index.native.js +35 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/useClickOutside.cjs +52 -0
- package/dist/cjs/useClickOutside.native.js +63 -0
- package/dist/cjs/useClickOutside.native.js.map +1 -0
- package/dist/cjs/useDebouncePrepend.cjs +66 -0
- package/dist/cjs/useDebouncePrepend.native.js +70 -0
- package/dist/cjs/useDebouncePrepend.native.js.map +1 -0
- package/dist/cjs/useDeepMemoizedObject.cjs +207 -0
- package/dist/cjs/useDeepMemoizedObject.native.js +258 -0
- package/dist/cjs/useDeepMemoizedObject.native.js.map +1 -0
- package/dist/cjs/useDeepMemoizedObject.test.cjs +321 -0
- package/dist/cjs/useDeepMemoizedObject.test.native.js +324 -0
- package/dist/cjs/useDeepMemoizedObject.test.native.js.map +1 -0
- package/dist/cjs/useDeferredBoolean.cjs +39 -0
- package/dist/cjs/useDeferredBoolean.native.js +42 -0
- package/dist/cjs/useDeferredBoolean.native.js.map +1 -0
- package/dist/cjs/useEffectOnceGlobally.cjs +45 -0
- package/dist/cjs/useEffectOnceGlobally.native.js +50 -0
- package/dist/cjs/useEffectOnceGlobally.native.js.map +1 -0
- package/dist/cjs/useEvent.cjs +33 -0
- package/dist/cjs/useEvent.native.js +41 -0
- package/dist/cjs/useEvent.native.js.map +1 -0
- package/dist/cjs/useIsMounted.cjs +35 -0
- package/dist/cjs/useIsMounted.native.js +38 -0
- package/dist/cjs/useIsMounted.native.js.map +1 -0
- package/dist/cjs/useLastValue.cjs +31 -0
- package/dist/cjs/useLastValue.native.js +34 -0
- package/dist/cjs/useLastValue.native.js.map +1 -0
- package/dist/cjs/useLastValueIf.cjs +38 -0
- package/dist/cjs/useLastValueIf.native.js +42 -0
- package/dist/cjs/useLastValueIf.native.js.map +1 -0
- package/dist/cjs/useMemoStable.cjs +35 -0
- package/dist/cjs/useMemoStable.native.js +39 -0
- package/dist/cjs/useMemoStable.native.js.map +1 -0
- package/dist/cjs/useMemoizedObjectList.cjs +64 -0
- package/dist/cjs/useMemoizedObjectList.native.js +86 -0
- package/dist/cjs/useMemoizedObjectList.native.js.map +1 -0
- package/dist/cjs/useThrottle.cjs +52 -0
- package/dist/cjs/useThrottle.native.js +59 -0
- package/dist/cjs/useThrottle.native.js.map +1 -0
- package/dist/cjs/useWarnIfDepsChange.cjs +65 -0
- package/dist/cjs/useWarnIfDepsChange.native.js +68 -0
- package/dist/cjs/useWarnIfDepsChange.native.js.map +1 -0
- package/dist/cjs/useWarnIfMemoChangesOften.cjs +43 -0
- package/dist/cjs/useWarnIfMemoChangesOften.native.js +48 -0
- package/dist/cjs/useWarnIfMemoChangesOften.native.js.map +1 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +14 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +14 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/useClickOutside.mjs +27 -0
- package/dist/esm/useClickOutside.mjs.map +1 -0
- package/dist/esm/useClickOutside.native.js +35 -0
- package/dist/esm/useClickOutside.native.js.map +1 -0
- package/dist/esm/useDebouncePrepend.mjs +41 -0
- package/dist/esm/useDebouncePrepend.mjs.map +1 -0
- package/dist/esm/useDebouncePrepend.native.js +42 -0
- package/dist/esm/useDebouncePrepend.native.js.map +1 -0
- package/dist/esm/useDeepMemoizedObject.mjs +180 -0
- package/dist/esm/useDeepMemoizedObject.mjs.map +1 -0
- package/dist/esm/useDeepMemoizedObject.native.js +228 -0
- package/dist/esm/useDeepMemoizedObject.native.js.map +1 -0
- package/dist/esm/useDeepMemoizedObject.test.mjs +322 -0
- package/dist/esm/useDeepMemoizedObject.test.mjs.map +1 -0
- package/dist/esm/useDeepMemoizedObject.test.native.js +322 -0
- package/dist/esm/useDeepMemoizedObject.test.native.js.map +1 -0
- package/dist/esm/useDeferredBoolean.mjs +14 -0
- package/dist/esm/useDeferredBoolean.mjs.map +1 -0
- package/dist/esm/useDeferredBoolean.native.js +14 -0
- package/dist/esm/useDeferredBoolean.native.js.map +1 -0
- package/dist/esm/useEffectOnceGlobally.mjs +20 -0
- package/dist/esm/useEffectOnceGlobally.mjs.map +1 -0
- package/dist/esm/useEffectOnceGlobally.native.js +22 -0
- package/dist/esm/useEffectOnceGlobally.native.js.map +1 -0
- package/dist/esm/useEvent.mjs +8 -0
- package/dist/esm/useEvent.mjs.map +1 -0
- package/dist/esm/useEvent.native.js +13 -0
- package/dist/esm/useEvent.native.js.map +1 -0
- package/dist/esm/useIsMounted.mjs +10 -0
- package/dist/esm/useIsMounted.mjs.map +1 -0
- package/dist/esm/useIsMounted.native.js +10 -0
- package/dist/esm/useIsMounted.native.js.map +1 -0
- package/dist/esm/useLastValue.mjs +6 -0
- package/dist/esm/useLastValue.mjs.map +1 -0
- package/dist/esm/useLastValue.native.js +6 -0
- package/dist/esm/useLastValue.native.js.map +1 -0
- package/dist/esm/useLastValueIf.mjs +13 -0
- package/dist/esm/useLastValueIf.mjs.map +1 -0
- package/dist/esm/useLastValueIf.native.js +14 -0
- package/dist/esm/useLastValueIf.native.js.map +1 -0
- package/dist/esm/useMemoStable.mjs +10 -0
- package/dist/esm/useMemoStable.mjs.map +1 -0
- package/dist/esm/useMemoStable.native.js +11 -0
- package/dist/esm/useMemoStable.native.js.map +1 -0
- package/dist/esm/useMemoizedObjectList.mjs +39 -0
- package/dist/esm/useMemoizedObjectList.mjs.map +1 -0
- package/dist/esm/useMemoizedObjectList.native.js +58 -0
- package/dist/esm/useMemoizedObjectList.native.js.map +1 -0
- package/dist/esm/useThrottle.mjs +27 -0
- package/dist/esm/useThrottle.mjs.map +1 -0
- package/dist/esm/useThrottle.native.js +31 -0
- package/dist/esm/useThrottle.native.js.map +1 -0
- package/dist/esm/useWarnIfDepsChange.mjs +40 -0
- package/dist/esm/useWarnIfDepsChange.mjs.map +1 -0
- package/dist/esm/useWarnIfDepsChange.native.js +40 -0
- package/dist/esm/useWarnIfDepsChange.native.js.map +1 -0
- package/dist/esm/useWarnIfMemoChangesOften.mjs +18 -0
- package/dist/esm/useWarnIfMemoChangesOften.mjs.map +1 -0
- package/dist/esm/useWarnIfMemoChangesOften.native.js +20 -0
- package/dist/esm/useWarnIfMemoChangesOften.native.js.map +1 -0
- package/package.json +58 -0
- package/src/index.ts +13 -0
- package/src/useClickOutside.ts +34 -0
- package/src/useDebouncePrepend.ts +63 -0
- package/src/useDeepMemoizedObject.test.ts +344 -0
- package/src/useDeepMemoizedObject.ts +231 -0
- package/src/useDeferredBoolean.tsx +15 -0
- package/src/useEffectOnceGlobally.ts +41 -0
- package/src/useEvent.ts +7 -0
- package/src/useIsMounted.ts +11 -0
- package/src/useLastValue.ts +5 -0
- package/src/useLastValueIf.ts +15 -0
- package/src/useMemoStable.ts +25 -0
- package/src/useMemoizedObjectList.ts +74 -0
- package/src/useThrottle.ts +36 -0
- package/src/useWarnIfDepsChange.ts +61 -0
- package/src/useWarnIfMemoChangesOften.ts +24 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
}), mod);
|
|
25
|
+
var useDeepMemoizedObject_exports = {};
|
|
26
|
+
__export(useDeepMemoizedObject_exports, {
|
|
27
|
+
deepMemoize: () => deepMemoize,
|
|
28
|
+
shouldBeImmutable: () => shouldBeImmutable,
|
|
29
|
+
useDeepMemoizedObject: () => useDeepMemoizedObject
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(useDeepMemoizedObject_exports);
|
|
32
|
+
var import_react = require("react");
|
|
33
|
+
function _type_of(obj) {
|
|
34
|
+
"@swc/helpers - typeof";
|
|
35
|
+
|
|
36
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
37
|
+
}
|
|
38
|
+
function shouldBeImmutable(path, immutableToNestedChanges) {
|
|
39
|
+
if (!immutableToNestedChanges) return false;
|
|
40
|
+
var currentPath = path.join(".");
|
|
41
|
+
for (var pattern in immutableToNestedChanges) {
|
|
42
|
+
if (immutableToNestedChanges[pattern] && currentPath === pattern) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
function deepMutateInPlace(target, source) {
|
|
49
|
+
if ((typeof target === "undefined" ? "undefined" : _type_of(target)) !== "object" || target === null || (typeof source === "undefined" ? "undefined" : _type_of(source)) !== "object" || source === null) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(target) && Array.isArray(source)) {
|
|
53
|
+
;
|
|
54
|
+
target.length = 0;
|
|
55
|
+
target.push(...source);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
for (var key in source) {
|
|
59
|
+
var targetValue = target[key];
|
|
60
|
+
var sourceValue = source[key];
|
|
61
|
+
if ((typeof sourceValue === "undefined" ? "undefined" : _type_of(sourceValue)) === "object" && sourceValue !== null && (typeof targetValue === "undefined" ? "undefined" : _type_of(targetValue)) === "object" && targetValue !== null) {
|
|
62
|
+
deepMutateInPlace(targetValue, sourceValue);
|
|
63
|
+
} else {
|
|
64
|
+
;
|
|
65
|
+
target[key] = sourceValue;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function deepMemoizeWithTracking(current, previous, path, immutableToNestedChanges) {
|
|
70
|
+
var parentIsImmutable = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : false;
|
|
71
|
+
if (current === previous) {
|
|
72
|
+
return {
|
|
73
|
+
value: previous,
|
|
74
|
+
hasChanges: false,
|
|
75
|
+
hasImmutableMutation: false
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if ((typeof current === "undefined" ? "undefined" : _type_of(current)) !== "object" || current === null) {
|
|
79
|
+
return {
|
|
80
|
+
value: current,
|
|
81
|
+
hasChanges: true,
|
|
82
|
+
hasImmutableMutation: false
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if ((typeof previous === "undefined" ? "undefined" : _type_of(previous)) !== "object" || previous === null) {
|
|
86
|
+
return {
|
|
87
|
+
value: current,
|
|
88
|
+
hasChanges: true,
|
|
89
|
+
hasImmutableMutation: false
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
var isCurrentImmutable = shouldBeImmutable(path, immutableToNestedChanges);
|
|
93
|
+
var shouldMutateInPlace = isCurrentImmutable || parentIsImmutable;
|
|
94
|
+
if (Array.isArray(current)) {
|
|
95
|
+
if (!Array.isArray(previous)) {
|
|
96
|
+
return {
|
|
97
|
+
value: current,
|
|
98
|
+
hasChanges: true,
|
|
99
|
+
hasImmutableMutation: false
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (current.length !== previous.length) {
|
|
103
|
+
return {
|
|
104
|
+
value: current,
|
|
105
|
+
hasChanges: true,
|
|
106
|
+
hasImmutableMutation: false
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
var hasChanges = false;
|
|
110
|
+
var hasImmutableMutation = false;
|
|
111
|
+
var memoizedArray = [];
|
|
112
|
+
for (var i = 0; i < current.length; i++) {
|
|
113
|
+
var itemPath = [...path, String(i)];
|
|
114
|
+
var result = deepMemoizeWithTracking(current[i], previous[i], itemPath, immutableToNestedChanges, false);
|
|
115
|
+
memoizedArray[i] = result.value;
|
|
116
|
+
if (result.hasChanges) {
|
|
117
|
+
hasChanges = true;
|
|
118
|
+
}
|
|
119
|
+
if (result.hasImmutableMutation) {
|
|
120
|
+
hasImmutableMutation = true;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (hasChanges || hasImmutableMutation) {
|
|
124
|
+
return {
|
|
125
|
+
value: memoizedArray,
|
|
126
|
+
hasChanges: true,
|
|
127
|
+
hasImmutableMutation: false
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
value: previous,
|
|
132
|
+
hasChanges: false,
|
|
133
|
+
hasImmutableMutation: false
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
var currentKeys = Object.keys(current);
|
|
137
|
+
var previousKeys = Object.keys(previous);
|
|
138
|
+
if (currentKeys.length !== previousKeys.length) {
|
|
139
|
+
return {
|
|
140
|
+
value: current,
|
|
141
|
+
hasChanges: true,
|
|
142
|
+
hasImmutableMutation: false
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
var keysMatch = currentKeys.every(function (key2) {
|
|
146
|
+
return key2 in previous;
|
|
147
|
+
});
|
|
148
|
+
if (!keysMatch) {
|
|
149
|
+
return {
|
|
150
|
+
value: current,
|
|
151
|
+
hasChanges: true,
|
|
152
|
+
hasImmutableMutation: false
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
var hasChanges1 = false;
|
|
156
|
+
var hasImmutableMutation1 = false;
|
|
157
|
+
var memoizedObject = {};
|
|
158
|
+
var _iteratorNormalCompletion = true,
|
|
159
|
+
_didIteratorError = false,
|
|
160
|
+
_iteratorError = void 0;
|
|
161
|
+
try {
|
|
162
|
+
for (var _iterator = currentKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
163
|
+
var key = _step.value;
|
|
164
|
+
var propPath = [...path, key];
|
|
165
|
+
var currentValue = current[key];
|
|
166
|
+
var previousValue = previous[key];
|
|
167
|
+
var result1 = deepMemoizeWithTracking(currentValue, previousValue, propPath, immutableToNestedChanges, shouldMutateInPlace);
|
|
168
|
+
memoizedObject[key] = result1.value;
|
|
169
|
+
if (result1.hasChanges) {
|
|
170
|
+
hasChanges1 = true;
|
|
171
|
+
}
|
|
172
|
+
if (result1.hasImmutableMutation) {
|
|
173
|
+
hasImmutableMutation1 = true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
} catch (err) {
|
|
177
|
+
_didIteratorError = true;
|
|
178
|
+
_iteratorError = err;
|
|
179
|
+
} finally {
|
|
180
|
+
try {
|
|
181
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
182
|
+
_iterator.return();
|
|
183
|
+
}
|
|
184
|
+
} finally {
|
|
185
|
+
if (_didIteratorError) {
|
|
186
|
+
throw _iteratorError;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (shouldMutateInPlace && (hasChanges1 || hasImmutableMutation1)) {
|
|
191
|
+
if (parentIsImmutable) {
|
|
192
|
+
deepMutateInPlace(previous, current);
|
|
193
|
+
} else {
|
|
194
|
+
var _iteratorNormalCompletion1 = true,
|
|
195
|
+
_didIteratorError1 = false,
|
|
196
|
+
_iteratorError1 = void 0;
|
|
197
|
+
try {
|
|
198
|
+
for (var _iterator1 = currentKeys[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
199
|
+
var key1 = _step1.value;
|
|
200
|
+
;
|
|
201
|
+
previous[key1] = memoizedObject[key1];
|
|
202
|
+
}
|
|
203
|
+
} catch (err) {
|
|
204
|
+
_didIteratorError1 = true;
|
|
205
|
+
_iteratorError1 = err;
|
|
206
|
+
} finally {
|
|
207
|
+
try {
|
|
208
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
209
|
+
_iterator1.return();
|
|
210
|
+
}
|
|
211
|
+
} finally {
|
|
212
|
+
if (_didIteratorError1) {
|
|
213
|
+
throw _iteratorError1;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
value: previous,
|
|
220
|
+
hasChanges: false,
|
|
221
|
+
hasImmutableMutation: true
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
if (hasChanges1 || hasImmutableMutation1) {
|
|
225
|
+
return {
|
|
226
|
+
value: memoizedObject,
|
|
227
|
+
hasChanges: true,
|
|
228
|
+
hasImmutableMutation: false
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
value: previous,
|
|
233
|
+
hasChanges: false,
|
|
234
|
+
hasImmutableMutation: false
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function deepMemoize(current, previous) {
|
|
238
|
+
var path = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [],
|
|
239
|
+
immutableToNestedChanges = arguments.length > 3 ? arguments[3] : void 0;
|
|
240
|
+
var result = deepMemoizeWithTracking(current, previous, path, immutableToNestedChanges, false);
|
|
241
|
+
if (path.length === 0 && result.hasImmutableMutation && !result.hasChanges) {
|
|
242
|
+
if (Array.isArray(result.value)) {
|
|
243
|
+
return [...result.value];
|
|
244
|
+
} else if (_type_of(result.value) === "object" && result.value !== null) {
|
|
245
|
+
return {
|
|
246
|
+
...result.value
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return result.value;
|
|
251
|
+
}
|
|
252
|
+
function useDeepMemoizedObject(value, options) {
|
|
253
|
+
var previousValueRef = (0, import_react.useRef)(value);
|
|
254
|
+
var memoizedValue = deepMemoize(value, previousValueRef.current, [], options === null || options === void 0 ? void 0 : options.immutableToNestedChanges);
|
|
255
|
+
previousValueRef.current = memoizedValue;
|
|
256
|
+
return memoizedValue;
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=useDeepMemoizedObject.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useDeepMemoizedObject_exports","__export","deepMemoize","shouldBeImmutable","useDeepMemoizedObject","module","exports","import_react","require","_type_of","obj","Symbol","constructor","path","immutableToNestedChanges","currentPath","join","pattern","deepMutateInPlace","target","source","Array","isArray","length","push","key","targetValue","sourceValue","deepMemoizeWithTracking","current","previous","parentIsImmutable","arguments","hasChanges","hasImmutableMutation","isCurrentImmutable","shouldMutateInPlace","memoizedArray","i","itemPath","String","result","currentKeys","Object","keys","previousKeys","keysMatch","every","key2","hasChanges1","hasImmutableMutation1","memoizedObject","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","iterator","_step","next","done","propPath","currentValue","previousValue","result1","err"],"sources":["../../src/useDeepMemoizedObject.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,6BAAA;AAAAC,QAAA,CAAAD,6BAAA;EAAAE,WAAA,EAAAA,CAAA,KAAAA,WAAA;EAAAC,iBAAA,EAAAA,CAAA,KAAAA,iBAAA;EAAAC,qBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAX,YAAuB,CAAAK,6BAAA;AAQhB,IAAAO,YA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OAAA,CAAAJ,GAAA;MAEA,IAAOqC,aAAO,GAAAhC,QAAA,CAAAL,GAAA;MAChB,IAAAsC,OAAA,GAAAnC,uBAAA,CAAAiC,YAAA,EAAAC,aAAA,EAAAF,QAAA,EAAA9C,wBAAA,EAAAsB,mBAAA;MAEOe,cAAS,CAAA1B,GAAA,IAAAsC,OAAyB,CAAAhE,KAAU;MACjD,IAAMgE,OAAA,CAAA9B,UAAA;QAEAgB,WAAA,OAAgB;MACpB;MACA,IAAAc,OAAA,CAAA7B,oBAAiB;QAChBgB,qBAAA;MACD;IACF;EAEA,SAAAc,GAAA;IAEAX,iBAAO;IACTC,cAAA,GAAAU,GAAA","ignoreList":[]}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
var import_vitest = require("vitest");
|
|
2
|
+
var import_useDeepMemoizedObject = require("./useDeepMemoizedObject.cjs");
|
|
3
|
+
function testMemoization(initialValue, options) {
|
|
4
|
+
let previousValue = initialValue;
|
|
5
|
+
return {
|
|
6
|
+
get current() {
|
|
7
|
+
return previousValue;
|
|
8
|
+
},
|
|
9
|
+
update(value) {
|
|
10
|
+
previousValue = (0, import_useDeepMemoizedObject.deepMemoize)(value, previousValue, [], options?.immutableToNestedChanges);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
(0, import_vitest.describe)("useDeepMemoizedObject", () => {
|
|
15
|
+
(0, import_vitest.it)("should preserve identity for unchanged primitives", () => {
|
|
16
|
+
const hook = testMemoization(42);
|
|
17
|
+
const firstResult = hook.current;
|
|
18
|
+
hook.update(42);
|
|
19
|
+
(0, import_vitest.expect)(hook.current).toBe(firstResult);
|
|
20
|
+
});
|
|
21
|
+
(0, import_vitest.it)("should preserve identity for unchanged objects", () => {
|
|
22
|
+
const obj = {
|
|
23
|
+
a: 1,
|
|
24
|
+
b: 2
|
|
25
|
+
};
|
|
26
|
+
const hook = testMemoization(obj);
|
|
27
|
+
const firstResult = hook.current;
|
|
28
|
+
hook.update({
|
|
29
|
+
a: 1,
|
|
30
|
+
b: 2
|
|
31
|
+
});
|
|
32
|
+
(0, import_vitest.expect)(hook.current).toBe(firstResult);
|
|
33
|
+
});
|
|
34
|
+
(0, import_vitest.it)("should preserve identity for unchanged arrays", () => {
|
|
35
|
+
const arr = [1, 2, 3];
|
|
36
|
+
const hook = testMemoization(arr);
|
|
37
|
+
const firstResult = hook.current;
|
|
38
|
+
hook.update([1, 2, 3]);
|
|
39
|
+
(0, import_vitest.expect)(hook.current).toBe(firstResult);
|
|
40
|
+
});
|
|
41
|
+
(0, import_vitest.it)("should handle nested object changes correctly", () => {
|
|
42
|
+
const initial = {
|
|
43
|
+
server: {
|
|
44
|
+
id: 1,
|
|
45
|
+
channels: [{
|
|
46
|
+
id: 1,
|
|
47
|
+
name: "general"
|
|
48
|
+
}, {
|
|
49
|
+
id: 2,
|
|
50
|
+
name: "random"
|
|
51
|
+
}, {
|
|
52
|
+
id: 3,
|
|
53
|
+
name: "tech"
|
|
54
|
+
}]
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const hook = testMemoization(initial);
|
|
58
|
+
const firstResult = hook.current;
|
|
59
|
+
const updated = {
|
|
60
|
+
server: {
|
|
61
|
+
id: 1,
|
|
62
|
+
channels: [{
|
|
63
|
+
id: 1,
|
|
64
|
+
name: "general-updated"
|
|
65
|
+
}, {
|
|
66
|
+
id: 2,
|
|
67
|
+
name: "random"
|
|
68
|
+
}, {
|
|
69
|
+
id: 3,
|
|
70
|
+
name: "tech"
|
|
71
|
+
}]
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
hook.update(updated);
|
|
75
|
+
const secondResult = hook.current;
|
|
76
|
+
(0, import_vitest.expect)(secondResult).not.toBe(firstResult);
|
|
77
|
+
(0, import_vitest.expect)(secondResult.server).not.toBe(firstResult.server);
|
|
78
|
+
(0, import_vitest.expect)(secondResult.server.channels).not.toBe(firstResult.server.channels);
|
|
79
|
+
(0, import_vitest.expect)(secondResult.server.channels[0]).not.toBe(firstResult.server.channels[0]);
|
|
80
|
+
(0, import_vitest.expect)(secondResult.server.channels[1]).toBe(firstResult.server.channels[1]);
|
|
81
|
+
(0, import_vitest.expect)(secondResult.server.channels[2]).toBe(firstResult.server.channels[2]);
|
|
82
|
+
});
|
|
83
|
+
(0, import_vitest.it)("should handle deep nested changes in arrays", () => {
|
|
84
|
+
const initial = {
|
|
85
|
+
server: {
|
|
86
|
+
channels: [{
|
|
87
|
+
id: 1,
|
|
88
|
+
messages: [{
|
|
89
|
+
id: 1,
|
|
90
|
+
text: "hi"
|
|
91
|
+
}, {
|
|
92
|
+
id: 2,
|
|
93
|
+
text: "hello"
|
|
94
|
+
}, {
|
|
95
|
+
id: 3,
|
|
96
|
+
text: "world",
|
|
97
|
+
reactions: [{
|
|
98
|
+
emoji: "\u{1F44D}",
|
|
99
|
+
count: 1
|
|
100
|
+
}, {
|
|
101
|
+
emoji: "\u2764\uFE0F",
|
|
102
|
+
count: 2
|
|
103
|
+
}, {
|
|
104
|
+
emoji: "\u{1F602}",
|
|
105
|
+
count: 3,
|
|
106
|
+
updatedAt: "2024-01-01"
|
|
107
|
+
}, {
|
|
108
|
+
emoji: "\u{1F389}",
|
|
109
|
+
count: 4
|
|
110
|
+
}]
|
|
111
|
+
}]
|
|
112
|
+
}]
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const hook = testMemoization(initial);
|
|
116
|
+
const firstResult = hook.current;
|
|
117
|
+
const updated = JSON.parse(JSON.stringify(initial));
|
|
118
|
+
updated.server.channels[0].messages[2].reactions[2].updatedAt = "2024-01-02";
|
|
119
|
+
hook.update(updated);
|
|
120
|
+
const secondResult = hook.current;
|
|
121
|
+
(0, import_vitest.expect)(secondResult).not.toBe(firstResult);
|
|
122
|
+
(0, import_vitest.expect)(secondResult.server).not.toBe(firstResult.server);
|
|
123
|
+
(0, import_vitest.expect)(secondResult.server.channels).not.toBe(firstResult.server.channels);
|
|
124
|
+
(0, import_vitest.expect)(secondResult.server.channels[0]).not.toBe(firstResult.server.channels[0]);
|
|
125
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages).not.toBe(firstResult.server.channels[0].messages);
|
|
126
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages[0]).toBe(firstResult.server.channels[0].messages[0]);
|
|
127
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages[1]).toBe(firstResult.server.channels[0].messages[1]);
|
|
128
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages[2]).not.toBe(firstResult.server.channels[0].messages[2]);
|
|
129
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages[2].reactions).not.toBe(firstResult.server.channels[0].messages[2].reactions);
|
|
130
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages[2].reactions[0]).toBe(firstResult.server.channels[0].messages[2].reactions[0]);
|
|
131
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages[2].reactions[1]).toBe(firstResult.server.channels[0].messages[2].reactions[1]);
|
|
132
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages[2].reactions[2]).not.toBe(firstResult.server.channels[0].messages[2].reactions[2]);
|
|
133
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages[2].reactions[3]).toBe(firstResult.server.channels[0].messages[2].reactions[3]);
|
|
134
|
+
});
|
|
135
|
+
(0, import_vitest.it)("should respect immutableToNestedChanges option", () => {
|
|
136
|
+
const initial = {
|
|
137
|
+
server: {
|
|
138
|
+
id: 1,
|
|
139
|
+
channels: [{
|
|
140
|
+
id: 1,
|
|
141
|
+
messages: [{
|
|
142
|
+
id: 1,
|
|
143
|
+
text: "hi"
|
|
144
|
+
}, {
|
|
145
|
+
id: 2,
|
|
146
|
+
text: "hello"
|
|
147
|
+
}, {
|
|
148
|
+
id: 3,
|
|
149
|
+
text: "world"
|
|
150
|
+
}, {
|
|
151
|
+
id: 4,
|
|
152
|
+
text: "foo"
|
|
153
|
+
}, {
|
|
154
|
+
id: 5,
|
|
155
|
+
text: "bar"
|
|
156
|
+
}, {
|
|
157
|
+
id: 6,
|
|
158
|
+
text: "baz",
|
|
159
|
+
reactions: [{
|
|
160
|
+
emoji: "\u{1F44D}",
|
|
161
|
+
count: 1
|
|
162
|
+
}, {
|
|
163
|
+
emoji: "\u2764\uFE0F",
|
|
164
|
+
count: 2
|
|
165
|
+
}, {
|
|
166
|
+
emoji: "\u{1F602}",
|
|
167
|
+
count: 3,
|
|
168
|
+
updatedAt: "2024-01-01"
|
|
169
|
+
}]
|
|
170
|
+
}]
|
|
171
|
+
}]
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const hook = testMemoization(initial, {
|
|
175
|
+
immutableToNestedChanges: {
|
|
176
|
+
server: true,
|
|
177
|
+
"server.channels.0": true
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
const firstResult = hook.current;
|
|
181
|
+
const originalChannels = firstResult.server.channels;
|
|
182
|
+
const originalChannel0 = firstResult.server.channels[0];
|
|
183
|
+
const originalMessages = firstResult.server.channels[0].messages;
|
|
184
|
+
const originalMessage5 = firstResult.server.channels[0].messages[5];
|
|
185
|
+
const originalReactions = firstResult.server.channels[0].messages[5].reactions;
|
|
186
|
+
const updated = JSON.parse(JSON.stringify(initial));
|
|
187
|
+
updated.server.channels[0].messages[5].reactions[2].updatedAt = "2024-01-02";
|
|
188
|
+
hook.update(updated);
|
|
189
|
+
const secondResult = hook.current;
|
|
190
|
+
(0, import_vitest.expect)(secondResult).not.toBe(firstResult);
|
|
191
|
+
(0, import_vitest.expect)(secondResult.server).toBe(firstResult.server);
|
|
192
|
+
(0, import_vitest.expect)(secondResult.server.channels).not.toBe(originalChannels);
|
|
193
|
+
(0, import_vitest.expect)(secondResult.server.channels[0]).toBe(originalChannel0);
|
|
194
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages).not.toBe(originalMessages);
|
|
195
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages[5]).not.toBe(originalMessage5);
|
|
196
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages[5].reactions).not.toBe(originalReactions);
|
|
197
|
+
(0, import_vitest.expect)(secondResult.server.channels[0].messages[5].reactions[2].updatedAt).toBe("2024-01-02");
|
|
198
|
+
});
|
|
199
|
+
(0, import_vitest.it)("should handle adding new properties to objects", () => {
|
|
200
|
+
const initial = {
|
|
201
|
+
a: 1,
|
|
202
|
+
b: 2
|
|
203
|
+
};
|
|
204
|
+
const hook = testMemoization(initial);
|
|
205
|
+
const firstResult = hook.current;
|
|
206
|
+
const updated = {
|
|
207
|
+
a: 1,
|
|
208
|
+
b: 2,
|
|
209
|
+
c: 3
|
|
210
|
+
};
|
|
211
|
+
hook.update(updated);
|
|
212
|
+
(0, import_vitest.expect)(hook.current).not.toBe(firstResult);
|
|
213
|
+
(0, import_vitest.expect)(hook.current).toEqual(updated);
|
|
214
|
+
});
|
|
215
|
+
(0, import_vitest.it)("should handle array length changes", () => {
|
|
216
|
+
const initial = [1, 2, 3];
|
|
217
|
+
const hook = testMemoization(initial);
|
|
218
|
+
const firstResult = hook.current;
|
|
219
|
+
hook.update([1, 2, 3, 4]);
|
|
220
|
+
(0, import_vitest.expect)(hook.current).not.toBe(firstResult);
|
|
221
|
+
(0, import_vitest.expect)(hook.current).toEqual([1, 2, 3, 4]);
|
|
222
|
+
});
|
|
223
|
+
(0, import_vitest.it)("should handle null and undefined values", () => {
|
|
224
|
+
const nullHook = testMemoization(null);
|
|
225
|
+
(0, import_vitest.expect)(nullHook.current).toBe(null);
|
|
226
|
+
nullHook.update(void 0);
|
|
227
|
+
(0, import_vitest.expect)(nullHook.current).toBe(void 0);
|
|
228
|
+
nullHook.update({
|
|
229
|
+
a: null,
|
|
230
|
+
b: void 0
|
|
231
|
+
});
|
|
232
|
+
const objResult = nullHook.current;
|
|
233
|
+
(0, import_vitest.expect)(objResult.a).toBe(null);
|
|
234
|
+
(0, import_vitest.expect)(objResult.b).toBe(void 0);
|
|
235
|
+
});
|
|
236
|
+
(0, import_vitest.it)("should preserve array items when only one changes", () => {
|
|
237
|
+
const initial = [{
|
|
238
|
+
id: 1,
|
|
239
|
+
name: "Alice"
|
|
240
|
+
}, {
|
|
241
|
+
id: 2,
|
|
242
|
+
name: "Bob"
|
|
243
|
+
}, {
|
|
244
|
+
id: 3,
|
|
245
|
+
name: "Charlie"
|
|
246
|
+
}];
|
|
247
|
+
const hook = testMemoization(initial);
|
|
248
|
+
const firstResult = hook.current;
|
|
249
|
+
const updated = [{
|
|
250
|
+
id: 1,
|
|
251
|
+
name: "Alice"
|
|
252
|
+
}, {
|
|
253
|
+
id: 2,
|
|
254
|
+
name: "Bobby"
|
|
255
|
+
}, {
|
|
256
|
+
id: 3,
|
|
257
|
+
name: "Charlie"
|
|
258
|
+
}];
|
|
259
|
+
hook.update(updated);
|
|
260
|
+
const secondResult = hook.current;
|
|
261
|
+
(0, import_vitest.expect)(secondResult).not.toBe(firstResult);
|
|
262
|
+
(0, import_vitest.expect)(secondResult[0]).toBe(firstResult[0]);
|
|
263
|
+
(0, import_vitest.expect)(secondResult[1]).not.toBe(firstResult[1]);
|
|
264
|
+
(0, import_vitest.expect)(secondResult[2]).toBe(firstResult[2]);
|
|
265
|
+
});
|
|
266
|
+
(0, import_vitest.it)("should handle complex immutableToNestedChanges patterns", () => {
|
|
267
|
+
const initial = {
|
|
268
|
+
app: {
|
|
269
|
+
settings: {
|
|
270
|
+
theme: "dark",
|
|
271
|
+
language: "en",
|
|
272
|
+
nested: {
|
|
273
|
+
deep: {
|
|
274
|
+
value: 1
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
const hook = testMemoization(initial, {
|
|
281
|
+
immutableToNestedChanges: {
|
|
282
|
+
"app.settings": true
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
const firstResult = hook.current;
|
|
286
|
+
const originalSettings = firstResult.app.settings;
|
|
287
|
+
const originalNested = firstResult.app.settings.nested;
|
|
288
|
+
const originalDeep = firstResult.app.settings.nested.deep;
|
|
289
|
+
const updated = JSON.parse(JSON.stringify(initial));
|
|
290
|
+
updated.app.settings.nested.deep.value = 2;
|
|
291
|
+
hook.update(updated);
|
|
292
|
+
const secondResult = hook.current;
|
|
293
|
+
(0, import_vitest.expect)(secondResult).not.toBe(firstResult);
|
|
294
|
+
(0, import_vitest.expect)(secondResult.app).not.toBe(firstResult.app);
|
|
295
|
+
(0, import_vitest.expect)(secondResult.app.settings).toBe(originalSettings);
|
|
296
|
+
(0, import_vitest.expect)(secondResult.app.settings.nested).toBe(originalNested);
|
|
297
|
+
(0, import_vitest.expect)(secondResult.app.settings.nested.deep).toBe(originalDeep);
|
|
298
|
+
(0, import_vitest.expect)(secondResult.app.settings.nested.deep.value).toBe(2);
|
|
299
|
+
});
|
|
300
|
+
(0, import_vitest.it)("should handle mixed arrays with objects and primitives", () => {
|
|
301
|
+
const initial = [1, "string", {
|
|
302
|
+
id: 1,
|
|
303
|
+
name: "object"
|
|
304
|
+
}, [1, 2, 3], null, void 0];
|
|
305
|
+
const hook = testMemoization(initial);
|
|
306
|
+
const firstResult = hook.current;
|
|
307
|
+
const updated = [1, "string", {
|
|
308
|
+
id: 1,
|
|
309
|
+
name: "updated"
|
|
310
|
+
}, [1, 2, 3], null, void 0];
|
|
311
|
+
hook.update(updated);
|
|
312
|
+
const secondResult = hook.current;
|
|
313
|
+
(0, import_vitest.expect)(secondResult).not.toBe(firstResult);
|
|
314
|
+
(0, import_vitest.expect)(secondResult[0]).toBe(1);
|
|
315
|
+
(0, import_vitest.expect)(secondResult[1]).toBe("string");
|
|
316
|
+
(0, import_vitest.expect)(secondResult[2]).not.toBe(firstResult[2]);
|
|
317
|
+
(0, import_vitest.expect)(secondResult[3]).toBe(firstResult[3]);
|
|
318
|
+
(0, import_vitest.expect)(secondResult[4]).toBe(null);
|
|
319
|
+
(0, import_vitest.expect)(secondResult[5]).toBe(void 0);
|
|
320
|
+
});
|
|
321
|
+
});
|