@take-out/hooks 0.4.3 → 0.4.5
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/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +7 -5
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/useClickOutside.cjs +24 -15
- package/dist/cjs/useClickOutside.native.js +34 -22
- package/dist/cjs/useClickOutside.native.js.map +1 -1
- package/dist/cjs/useDebouncePrepend.cjs +47 -27
- package/dist/cjs/useDebouncePrepend.native.js +48 -32
- package/dist/cjs/useDebouncePrepend.native.js.map +1 -1
- package/dist/cjs/useDeepMemoizedObject.cjs +154 -95
- package/dist/cjs/useDeepMemoizedObject.native.js +177 -111
- package/dist/cjs/useDeepMemoizedObject.native.js.map +1 -1
- package/dist/cjs/useDeepMemoizedObject.test.cjs +269 -199
- package/dist/cjs/useDeepMemoizedObject.test.native.js +265 -202
- package/dist/cjs/useDeepMemoizedObject.test.native.js.map +1 -1
- package/dist/cjs/useDeferredBoolean.cjs +20 -15
- package/dist/cjs/useDeferredBoolean.native.js +22 -17
- package/dist/cjs/useDeferredBoolean.native.js.map +1 -1
- package/dist/cjs/useEffectOnceGlobally.cjs +24 -12
- package/dist/cjs/useEffectOnceGlobally.native.js +27 -15
- package/dist/cjs/useEffectOnceGlobally.native.js.map +1 -1
- package/dist/cjs/useEvent.cjs +14 -11
- package/dist/cjs/useEvent.native.js +17 -12
- package/dist/cjs/useEvent.native.js.map +1 -1
- package/dist/cjs/useIsMounted.cjs +17 -14
- package/dist/cjs/useIsMounted.native.js +20 -17
- package/dist/cjs/useIsMounted.native.js.map +1 -1
- package/dist/cjs/useLastValue.cjs +13 -11
- package/dist/cjs/useLastValue.native.js +13 -11
- package/dist/cjs/useLastValue.native.js.map +1 -1
- package/dist/cjs/useLastValueIf.cjs +21 -14
- package/dist/cjs/useLastValueIf.native.js +21 -14
- package/dist/cjs/useLastValueIf.native.js.map +1 -1
- package/dist/cjs/useMemoStable.cjs +17 -14
- package/dist/cjs/useMemoStable.native.js +17 -14
- package/dist/cjs/useMemoStable.native.js.map +1 -1
- package/dist/cjs/useMemoizedObjectList.cjs +45 -29
- package/dist/cjs/useMemoizedObjectList.native.js +60 -39
- package/dist/cjs/useMemoizedObjectList.native.js.map +1 -1
- package/dist/cjs/useThrottle.cjs +34 -21
- package/dist/cjs/useThrottle.native.js +41 -27
- package/dist/cjs/useThrottle.native.js.map +1 -1
- package/dist/cjs/useWarnIfDepsChange.cjs +38 -27
- package/dist/cjs/useWarnIfDepsChange.native.js +38 -28
- package/dist/cjs/useWarnIfDepsChange.native.js.map +1 -1
- package/dist/cjs/useWarnIfMemoChangesOften.cjs +24 -15
- package/dist/cjs/useWarnIfMemoChangesOften.native.js +27 -21
- package/dist/cjs/useWarnIfMemoChangesOften.native.js.map +1 -1
- package/dist/esm/useClickOutside.mjs +10 -3
- package/dist/esm/useClickOutside.mjs.map +1 -1
- package/dist/esm/useClickOutside.native.js +20 -10
- package/dist/esm/useClickOutside.native.js.map +1 -1
- package/dist/esm/useDebouncePrepend.mjs +33 -15
- package/dist/esm/useDebouncePrepend.mjs.map +1 -1
- package/dist/esm/useDebouncePrepend.native.js +34 -20
- package/dist/esm/useDebouncePrepend.native.js.map +1 -1
- package/dist/esm/useDeepMemoizedObject.mjs +142 -85
- package/dist/esm/useDeepMemoizedObject.mjs.map +1 -1
- package/dist/esm/useDeepMemoizedObject.native.js +165 -101
- package/dist/esm/useDeepMemoizedObject.native.js.map +1 -1
- package/dist/esm/useDeepMemoizedObject.test.mjs +267 -197
- package/dist/esm/useDeepMemoizedObject.test.mjs.map +1 -1
- package/dist/esm/useDeepMemoizedObject.test.native.js +263 -200
- package/dist/esm/useDeepMemoizedObject.test.native.js.map +1 -1
- package/dist/esm/useDeferredBoolean.mjs +8 -5
- package/dist/esm/useDeferredBoolean.mjs.map +1 -1
- package/dist/esm/useDeferredBoolean.native.js +8 -5
- package/dist/esm/useDeferredBoolean.native.js.map +1 -1
- package/dist/esm/useEffectOnceGlobally.mjs +12 -2
- package/dist/esm/useEffectOnceGlobally.mjs.map +1 -1
- package/dist/esm/useEffectOnceGlobally.native.js +13 -3
- package/dist/esm/useEffectOnceGlobally.native.js.map +1 -1
- package/dist/esm/useEvent.mjs +2 -1
- package/dist/esm/useEvent.mjs.map +1 -1
- package/dist/esm/useEvent.native.js +5 -2
- package/dist/esm/useEvent.native.js.map +1 -1
- package/dist/esm/useIsMounted.mjs +5 -4
- package/dist/esm/useIsMounted.mjs.map +1 -1
- package/dist/esm/useIsMounted.native.js +5 -4
- package/dist/esm/useIsMounted.native.js.map +1 -1
- package/dist/esm/useLastValue.mjs +1 -1
- package/dist/esm/useLastValue.mjs.map +1 -1
- package/dist/esm/useLastValue.native.js +1 -1
- package/dist/esm/useLastValue.native.js.map +1 -1
- package/dist/esm/useLastValueIf.mjs +9 -4
- package/dist/esm/useLastValueIf.mjs.map +1 -1
- package/dist/esm/useLastValueIf.native.js +9 -4
- package/dist/esm/useLastValueIf.native.js.map +1 -1
- package/dist/esm/useMemoStable.mjs +3 -2
- package/dist/esm/useMemoStable.mjs.map +1 -1
- package/dist/esm/useMemoStable.native.js +3 -2
- package/dist/esm/useMemoStable.native.js.map +1 -1
- package/dist/esm/useMemoizedObjectList.mjs +31 -17
- package/dist/esm/useMemoizedObjectList.mjs.map +1 -1
- package/dist/esm/useMemoizedObjectList.native.js +46 -27
- package/dist/esm/useMemoizedObjectList.native.js.map +1 -1
- package/dist/esm/useThrottle.mjs +20 -9
- package/dist/esm/useThrottle.mjs.map +1 -1
- package/dist/esm/useThrottle.native.js +24 -12
- package/dist/esm/useThrottle.native.js.map +1 -1
- package/dist/esm/useWarnIfDepsChange.mjs +24 -15
- package/dist/esm/useWarnIfDepsChange.mjs.map +1 -1
- package/dist/esm/useWarnIfDepsChange.native.js +24 -16
- package/dist/esm/useWarnIfDepsChange.native.js.map +1 -1
- package/dist/esm/useWarnIfMemoChangesOften.mjs +10 -3
- package/dist/esm/useWarnIfMemoChangesOften.mjs.map +1 -1
- package/dist/esm/useWarnIfMemoChangesOften.native.js +10 -6
- package/dist/esm/useWarnIfMemoChangesOften.native.js.map +1 -1
- package/package.json +3 -3
|
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
14
|
get: () => from[key],
|
|
14
15
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
21
|
+
value: true
|
|
20
22
|
}), mod);
|
|
21
23
|
var useDeepMemoizedObject_exports = {};
|
|
22
24
|
__export(useDeepMemoizedObject_exports, {
|
|
@@ -27,122 +29,179 @@ __export(useDeepMemoizedObject_exports, {
|
|
|
27
29
|
module.exports = __toCommonJS(useDeepMemoizedObject_exports);
|
|
28
30
|
var import_react = require("react");
|
|
29
31
|
function shouldBeImmutable(path, immutableToNestedChanges) {
|
|
30
|
-
if (!immutableToNestedChanges) return
|
|
32
|
+
if (!immutableToNestedChanges) return false;
|
|
31
33
|
const currentPath = path.join(".");
|
|
32
|
-
for (const pattern in immutableToNestedChanges)
|
|
33
|
-
|
|
34
|
+
for (const pattern in immutableToNestedChanges) {
|
|
35
|
+
if (immutableToNestedChanges[pattern] && currentPath === pattern) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
34
40
|
}
|
|
35
41
|
function deepMutateInPlace(target, source) {
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
if (typeof target !== "object" || target === null || typeof source !== "object" || source === null) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(target) && Array.isArray(source)) {
|
|
46
|
+
;
|
|
47
|
+
target.length = 0;
|
|
48
|
+
target.push(...source);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
for (const key in source) {
|
|
52
|
+
const targetValue = target[key];
|
|
53
|
+
const sourceValue = source[key];
|
|
54
|
+
if (typeof sourceValue === "object" && sourceValue !== null && typeof targetValue === "object" && targetValue !== null) {
|
|
55
|
+
deepMutateInPlace(targetValue, sourceValue);
|
|
56
|
+
} else {
|
|
57
|
+
;
|
|
58
|
+
target[key] = sourceValue;
|
|
45
59
|
}
|
|
46
60
|
}
|
|
47
61
|
}
|
|
48
|
-
function deepMemoizeWithTracking(current, previous, path, immutableToNestedChanges, parentIsImmutable =
|
|
49
|
-
if (current === previous)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
if (typeof previous != "object" || previous === null) return {
|
|
60
|
-
value: current,
|
|
61
|
-
hasChanges: !0,
|
|
62
|
-
hasImmutableMutation: !1
|
|
63
|
-
};
|
|
64
|
-
const shouldMutateInPlace = shouldBeImmutable(path, immutableToNestedChanges) || parentIsImmutable;
|
|
65
|
-
if (Array.isArray(current)) {
|
|
66
|
-
if (!Array.isArray(previous)) return {
|
|
62
|
+
function deepMemoizeWithTracking(current, previous, path, immutableToNestedChanges, parentIsImmutable = false) {
|
|
63
|
+
if (current === previous) {
|
|
64
|
+
return {
|
|
65
|
+
value: previous,
|
|
66
|
+
hasChanges: false,
|
|
67
|
+
hasImmutableMutation: false
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (typeof current !== "object" || current === null) {
|
|
71
|
+
return {
|
|
67
72
|
value: current,
|
|
68
|
-
hasChanges:
|
|
69
|
-
hasImmutableMutation:
|
|
73
|
+
hasChanges: true,
|
|
74
|
+
hasImmutableMutation: false
|
|
70
75
|
};
|
|
71
|
-
|
|
76
|
+
}
|
|
77
|
+
if (typeof previous !== "object" || previous === null) {
|
|
78
|
+
return {
|
|
72
79
|
value: current,
|
|
73
|
-
hasChanges:
|
|
74
|
-
hasImmutableMutation:
|
|
80
|
+
hasChanges: true,
|
|
81
|
+
hasImmutableMutation: false
|
|
75
82
|
};
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
}
|
|
84
|
+
const isCurrentImmutable = shouldBeImmutable(path, immutableToNestedChanges);
|
|
85
|
+
const shouldMutateInPlace = isCurrentImmutable || parentIsImmutable;
|
|
86
|
+
if (Array.isArray(current)) {
|
|
87
|
+
if (!Array.isArray(previous)) {
|
|
88
|
+
return {
|
|
89
|
+
value: current,
|
|
90
|
+
hasChanges: true,
|
|
91
|
+
hasImmutableMutation: false
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (current.length !== previous.length) {
|
|
95
|
+
return {
|
|
96
|
+
value: current,
|
|
97
|
+
hasChanges: true,
|
|
98
|
+
hasImmutableMutation: false
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
let hasChanges2 = false;
|
|
102
|
+
let hasImmutableMutation2 = false;
|
|
78
103
|
const memoizedArray = [];
|
|
79
104
|
for (let i = 0; i < current.length; i++) {
|
|
80
|
-
const itemPath = [...path, String(i)]
|
|
81
|
-
|
|
82
|
-
memoizedArray[i] = result.value
|
|
105
|
+
const itemPath = [...path, String(i)];
|
|
106
|
+
const result = deepMemoizeWithTracking(current[i], previous[i], itemPath, immutableToNestedChanges, false);
|
|
107
|
+
memoizedArray[i] = result.value;
|
|
108
|
+
if (result.hasChanges) {
|
|
109
|
+
hasChanges2 = true;
|
|
110
|
+
}
|
|
111
|
+
if (result.hasImmutableMutation) {
|
|
112
|
+
hasImmutableMutation2 = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (hasChanges2 || hasImmutableMutation2) {
|
|
116
|
+
return {
|
|
117
|
+
value: memoizedArray,
|
|
118
|
+
hasChanges: true,
|
|
119
|
+
hasImmutableMutation: false
|
|
120
|
+
};
|
|
83
121
|
}
|
|
84
|
-
return
|
|
85
|
-
value: memoizedArray,
|
|
86
|
-
hasChanges: !0,
|
|
87
|
-
hasImmutableMutation: !1
|
|
88
|
-
} : {
|
|
122
|
+
return {
|
|
89
123
|
value: previous,
|
|
90
|
-
hasChanges:
|
|
91
|
-
hasImmutableMutation:
|
|
124
|
+
hasChanges: false,
|
|
125
|
+
hasImmutableMutation: false
|
|
92
126
|
};
|
|
93
127
|
}
|
|
94
|
-
const currentKeys = Object.keys(current)
|
|
95
|
-
|
|
96
|
-
if (currentKeys.length !== previousKeys.length)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
128
|
+
const currentKeys = Object.keys(current);
|
|
129
|
+
const previousKeys = Object.keys(previous);
|
|
130
|
+
if (currentKeys.length !== previousKeys.length) {
|
|
131
|
+
return {
|
|
132
|
+
value: current,
|
|
133
|
+
hasChanges: true,
|
|
134
|
+
hasImmutableMutation: false
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const keysMatch = currentKeys.every(key => key in previous);
|
|
138
|
+
if (!keysMatch) {
|
|
139
|
+
return {
|
|
140
|
+
value: current,
|
|
141
|
+
hasChanges: true,
|
|
142
|
+
hasImmutableMutation: false
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
let hasChanges = false;
|
|
146
|
+
let hasImmutableMutation = false;
|
|
108
147
|
const memoizedObject = {};
|
|
109
148
|
for (const key of currentKeys) {
|
|
110
|
-
const propPath = [...path, key]
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
memoizedObject[key] = result.value
|
|
149
|
+
const propPath = [...path, key];
|
|
150
|
+
const currentValue = current[key];
|
|
151
|
+
const previousValue = previous[key];
|
|
152
|
+
const result = deepMemoizeWithTracking(currentValue, previousValue, propPath, immutableToNestedChanges, shouldMutateInPlace);
|
|
153
|
+
memoizedObject[key] = result.value;
|
|
154
|
+
if (result.hasChanges) {
|
|
155
|
+
hasChanges = true;
|
|
156
|
+
}
|
|
157
|
+
if (result.hasImmutableMutation) {
|
|
158
|
+
hasImmutableMutation = true;
|
|
159
|
+
}
|
|
115
160
|
}
|
|
116
161
|
if (shouldMutateInPlace && (hasChanges || hasImmutableMutation)) {
|
|
117
|
-
if (parentIsImmutable)
|
|
162
|
+
if (parentIsImmutable) {
|
|
163
|
+
deepMutateInPlace(previous, current);
|
|
164
|
+
} else {
|
|
165
|
+
for (const key of currentKeys) {
|
|
166
|
+
;
|
|
167
|
+
previous[key] = memoizedObject[key];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
118
170
|
return {
|
|
119
171
|
value: previous,
|
|
120
|
-
hasChanges:
|
|
121
|
-
hasImmutableMutation:
|
|
172
|
+
hasChanges: false,
|
|
173
|
+
hasImmutableMutation: true
|
|
122
174
|
};
|
|
123
175
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
176
|
+
if (hasChanges || hasImmutableMutation) {
|
|
177
|
+
return {
|
|
178
|
+
value: memoizedObject,
|
|
179
|
+
hasChanges: true,
|
|
180
|
+
hasImmutableMutation: false
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
129
184
|
value: previous,
|
|
130
|
-
hasChanges:
|
|
131
|
-
hasImmutableMutation:
|
|
185
|
+
hasChanges: false,
|
|
186
|
+
hasImmutableMutation: false
|
|
132
187
|
};
|
|
133
188
|
}
|
|
134
189
|
function deepMemoize(current, previous, path = [], immutableToNestedChanges) {
|
|
135
|
-
const result = deepMemoizeWithTracking(current, previous, path, immutableToNestedChanges,
|
|
190
|
+
const result = deepMemoizeWithTracking(current, previous, path, immutableToNestedChanges, false);
|
|
136
191
|
if (path.length === 0 && result.hasImmutableMutation && !result.hasChanges) {
|
|
137
|
-
if (Array.isArray(result.value))
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
192
|
+
if (Array.isArray(result.value)) {
|
|
193
|
+
return [...result.value];
|
|
194
|
+
} else if (typeof result.value === "object" && result.value !== null) {
|
|
195
|
+
return {
|
|
196
|
+
...result.value
|
|
197
|
+
};
|
|
198
|
+
}
|
|
141
199
|
}
|
|
142
200
|
return result.value;
|
|
143
201
|
}
|
|
144
202
|
function useDeepMemoizedObject(value, options) {
|
|
145
|
-
const previousValueRef = (0, import_react.useRef)(value)
|
|
146
|
-
|
|
147
|
-
|
|
203
|
+
const previousValueRef = (0, import_react.useRef)(value);
|
|
204
|
+
const memoizedValue = deepMemoize(value, previousValueRef.current, [], options?.immutableToNestedChanges);
|
|
205
|
+
previousValueRef.current = memoizedValue;
|
|
206
|
+
return memoizedValue;
|
|
148
207
|
}
|
|
@@ -5,20 +5,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value:
|
|
23
|
+
value: true
|
|
22
24
|
}), mod);
|
|
23
25
|
var useDeepMemoizedObject_exports = {};
|
|
24
26
|
__export(useDeepMemoizedObject_exports, {
|
|
@@ -31,162 +33,226 @@ var import_react = require("react");
|
|
|
31
33
|
function _type_of(obj) {
|
|
32
34
|
"@swc/helpers - typeof";
|
|
33
35
|
|
|
34
|
-
return obj && typeof Symbol
|
|
36
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
35
37
|
}
|
|
36
38
|
function shouldBeImmutable(path, immutableToNestedChanges) {
|
|
37
|
-
if (!immutableToNestedChanges) return
|
|
39
|
+
if (!immutableToNestedChanges) return false;
|
|
38
40
|
var currentPath = path.join(".");
|
|
39
|
-
for (var pattern in immutableToNestedChanges)
|
|
40
|
-
|
|
41
|
+
for (var pattern in immutableToNestedChanges) {
|
|
42
|
+
if (immutableToNestedChanges[pattern] && currentPath === pattern) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
41
47
|
}
|
|
42
48
|
function deepMutateInPlace(target, source) {
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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;
|
|
52
66
|
}
|
|
53
67
|
}
|
|
54
68
|
}
|
|
55
69
|
function deepMemoizeWithTracking(current, previous, path, immutableToNestedChanges) {
|
|
56
|
-
var parentIsImmutable = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] :
|
|
57
|
-
if (current === previous)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
if ((typeof previous > "u" ? "undefined" : _type_of(previous)) !== "object" || previous === null) return {
|
|
68
|
-
value: current,
|
|
69
|
-
hasChanges: !0,
|
|
70
|
-
hasImmutableMutation: !1
|
|
71
|
-
};
|
|
72
|
-
var isCurrentImmutable = shouldBeImmutable(path, immutableToNestedChanges),
|
|
73
|
-
shouldMutateInPlace = isCurrentImmutable || parentIsImmutable;
|
|
74
|
-
if (Array.isArray(current)) {
|
|
75
|
-
if (!Array.isArray(previous)) return {
|
|
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 {
|
|
76
80
|
value: current,
|
|
77
|
-
hasChanges:
|
|
78
|
-
hasImmutableMutation:
|
|
81
|
+
hasChanges: true,
|
|
82
|
+
hasImmutableMutation: false
|
|
79
83
|
};
|
|
80
|
-
|
|
84
|
+
}
|
|
85
|
+
if ((typeof previous === "undefined" ? "undefined" : _type_of(previous)) !== "object" || previous === null) {
|
|
86
|
+
return {
|
|
81
87
|
value: current,
|
|
82
|
-
hasChanges:
|
|
83
|
-
hasImmutableMutation:
|
|
88
|
+
hasChanges: true,
|
|
89
|
+
hasImmutableMutation: false
|
|
84
90
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
};
|
|
89
108
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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 {
|
|
95
131
|
value: previous,
|
|
96
|
-
hasChanges:
|
|
97
|
-
hasImmutableMutation:
|
|
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
|
|
98
143
|
};
|
|
99
144
|
}
|
|
100
|
-
var currentKeys = Object.keys(current),
|
|
101
|
-
previousKeys = Object.keys(previous);
|
|
102
|
-
if (currentKeys.length !== previousKeys.length) return {
|
|
103
|
-
value: current,
|
|
104
|
-
hasChanges: !0,
|
|
105
|
-
hasImmutableMutation: !1
|
|
106
|
-
};
|
|
107
145
|
var keysMatch = currentKeys.every(function (key2) {
|
|
108
146
|
return key2 in previous;
|
|
109
147
|
});
|
|
110
|
-
if (!keysMatch)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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,
|
|
120
160
|
_iteratorError = void 0;
|
|
121
161
|
try {
|
|
122
|
-
for (var _iterator = currentKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion =
|
|
123
|
-
var key = _step.value
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
memoizedObject[key] = result1.value
|
|
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
|
+
}
|
|
129
175
|
}
|
|
130
176
|
} catch (err) {
|
|
131
|
-
_didIteratorError =
|
|
177
|
+
_didIteratorError = true;
|
|
178
|
+
_iteratorError = err;
|
|
132
179
|
} finally {
|
|
133
180
|
try {
|
|
134
|
-
!_iteratorNormalCompletion && _iterator.return != null
|
|
181
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
182
|
+
_iterator.return();
|
|
183
|
+
}
|
|
135
184
|
} finally {
|
|
136
|
-
if (_didIteratorError)
|
|
185
|
+
if (_didIteratorError) {
|
|
186
|
+
throw _iteratorError;
|
|
187
|
+
}
|
|
137
188
|
}
|
|
138
189
|
}
|
|
139
190
|
if (shouldMutateInPlace && (hasChanges1 || hasImmutableMutation1)) {
|
|
140
|
-
if (parentIsImmutable)
|
|
141
|
-
|
|
142
|
-
|
|
191
|
+
if (parentIsImmutable) {
|
|
192
|
+
deepMutateInPlace(previous, current);
|
|
193
|
+
} else {
|
|
194
|
+
var _iteratorNormalCompletion1 = true,
|
|
195
|
+
_didIteratorError1 = false,
|
|
143
196
|
_iteratorError1 = void 0;
|
|
144
197
|
try {
|
|
145
|
-
for (var _iterator1 = currentKeys[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 =
|
|
198
|
+
for (var _iterator1 = currentKeys[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
146
199
|
var key1 = _step1.value;
|
|
200
|
+
;
|
|
147
201
|
previous[key1] = memoizedObject[key1];
|
|
148
202
|
}
|
|
149
203
|
} catch (err) {
|
|
150
|
-
_didIteratorError1 =
|
|
204
|
+
_didIteratorError1 = true;
|
|
205
|
+
_iteratorError1 = err;
|
|
151
206
|
} finally {
|
|
152
207
|
try {
|
|
153
|
-
!_iteratorNormalCompletion1 && _iterator1.return != null
|
|
208
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
209
|
+
_iterator1.return();
|
|
210
|
+
}
|
|
154
211
|
} finally {
|
|
155
|
-
if (_didIteratorError1)
|
|
212
|
+
if (_didIteratorError1) {
|
|
213
|
+
throw _iteratorError1;
|
|
214
|
+
}
|
|
156
215
|
}
|
|
157
216
|
}
|
|
158
217
|
}
|
|
159
218
|
return {
|
|
160
219
|
value: previous,
|
|
161
|
-
hasChanges:
|
|
162
|
-
hasImmutableMutation:
|
|
220
|
+
hasChanges: false,
|
|
221
|
+
hasImmutableMutation: true
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
if (hasChanges1 || hasImmutableMutation1) {
|
|
225
|
+
return {
|
|
226
|
+
value: memoizedObject,
|
|
227
|
+
hasChanges: true,
|
|
228
|
+
hasImmutableMutation: false
|
|
163
229
|
};
|
|
164
230
|
}
|
|
165
|
-
return
|
|
166
|
-
value: memoizedObject,
|
|
167
|
-
hasChanges: !0,
|
|
168
|
-
hasImmutableMutation: !1
|
|
169
|
-
} : {
|
|
231
|
+
return {
|
|
170
232
|
value: previous,
|
|
171
|
-
hasChanges:
|
|
172
|
-
hasImmutableMutation:
|
|
233
|
+
hasChanges: false,
|
|
234
|
+
hasImmutableMutation: false
|
|
173
235
|
};
|
|
174
236
|
}
|
|
175
237
|
function deepMemoize(current, previous) {
|
|
176
238
|
var path = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [],
|
|
177
|
-
immutableToNestedChanges = arguments.length > 3 ? arguments[3] : void 0
|
|
178
|
-
|
|
239
|
+
immutableToNestedChanges = arguments.length > 3 ? arguments[3] : void 0;
|
|
240
|
+
var result = deepMemoizeWithTracking(current, previous, path, immutableToNestedChanges, false);
|
|
179
241
|
if (path.length === 0 && result.hasImmutableMutation && !result.hasChanges) {
|
|
180
|
-
if (Array.isArray(result.value))
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
+
}
|
|
184
249
|
}
|
|
185
250
|
return result.value;
|
|
186
251
|
}
|
|
187
252
|
function useDeepMemoizedObject(value, options) {
|
|
188
|
-
var previousValueRef = (0, import_react.useRef)(value)
|
|
189
|
-
|
|
190
|
-
|
|
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;
|
|
191
257
|
}
|
|
192
258
|
//# sourceMappingURL=useDeepMemoizedObject.native.js.map
|