@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.
Files changed (109) hide show
  1. package/dist/cjs/index.cjs +7 -5
  2. package/dist/cjs/index.native.js +7 -5
  3. package/dist/cjs/index.native.js.map +1 -1
  4. package/dist/cjs/useClickOutside.cjs +24 -15
  5. package/dist/cjs/useClickOutside.native.js +34 -22
  6. package/dist/cjs/useClickOutside.native.js.map +1 -1
  7. package/dist/cjs/useDebouncePrepend.cjs +47 -27
  8. package/dist/cjs/useDebouncePrepend.native.js +48 -32
  9. package/dist/cjs/useDebouncePrepend.native.js.map +1 -1
  10. package/dist/cjs/useDeepMemoizedObject.cjs +154 -95
  11. package/dist/cjs/useDeepMemoizedObject.native.js +177 -111
  12. package/dist/cjs/useDeepMemoizedObject.native.js.map +1 -1
  13. package/dist/cjs/useDeepMemoizedObject.test.cjs +269 -199
  14. package/dist/cjs/useDeepMemoizedObject.test.native.js +265 -202
  15. package/dist/cjs/useDeepMemoizedObject.test.native.js.map +1 -1
  16. package/dist/cjs/useDeferredBoolean.cjs +20 -15
  17. package/dist/cjs/useDeferredBoolean.native.js +22 -17
  18. package/dist/cjs/useDeferredBoolean.native.js.map +1 -1
  19. package/dist/cjs/useEffectOnceGlobally.cjs +24 -12
  20. package/dist/cjs/useEffectOnceGlobally.native.js +27 -15
  21. package/dist/cjs/useEffectOnceGlobally.native.js.map +1 -1
  22. package/dist/cjs/useEvent.cjs +14 -11
  23. package/dist/cjs/useEvent.native.js +17 -12
  24. package/dist/cjs/useEvent.native.js.map +1 -1
  25. package/dist/cjs/useIsMounted.cjs +17 -14
  26. package/dist/cjs/useIsMounted.native.js +20 -17
  27. package/dist/cjs/useIsMounted.native.js.map +1 -1
  28. package/dist/cjs/useLastValue.cjs +13 -11
  29. package/dist/cjs/useLastValue.native.js +13 -11
  30. package/dist/cjs/useLastValue.native.js.map +1 -1
  31. package/dist/cjs/useLastValueIf.cjs +21 -14
  32. package/dist/cjs/useLastValueIf.native.js +21 -14
  33. package/dist/cjs/useLastValueIf.native.js.map +1 -1
  34. package/dist/cjs/useMemoStable.cjs +17 -14
  35. package/dist/cjs/useMemoStable.native.js +17 -14
  36. package/dist/cjs/useMemoStable.native.js.map +1 -1
  37. package/dist/cjs/useMemoizedObjectList.cjs +45 -29
  38. package/dist/cjs/useMemoizedObjectList.native.js +60 -39
  39. package/dist/cjs/useMemoizedObjectList.native.js.map +1 -1
  40. package/dist/cjs/useThrottle.cjs +34 -21
  41. package/dist/cjs/useThrottle.native.js +41 -27
  42. package/dist/cjs/useThrottle.native.js.map +1 -1
  43. package/dist/cjs/useWarnIfDepsChange.cjs +38 -27
  44. package/dist/cjs/useWarnIfDepsChange.native.js +38 -28
  45. package/dist/cjs/useWarnIfDepsChange.native.js.map +1 -1
  46. package/dist/cjs/useWarnIfMemoChangesOften.cjs +24 -15
  47. package/dist/cjs/useWarnIfMemoChangesOften.native.js +27 -21
  48. package/dist/cjs/useWarnIfMemoChangesOften.native.js.map +1 -1
  49. package/dist/esm/useClickOutside.mjs +10 -3
  50. package/dist/esm/useClickOutside.mjs.map +1 -1
  51. package/dist/esm/useClickOutside.native.js +20 -10
  52. package/dist/esm/useClickOutside.native.js.map +1 -1
  53. package/dist/esm/useDebouncePrepend.mjs +33 -15
  54. package/dist/esm/useDebouncePrepend.mjs.map +1 -1
  55. package/dist/esm/useDebouncePrepend.native.js +34 -20
  56. package/dist/esm/useDebouncePrepend.native.js.map +1 -1
  57. package/dist/esm/useDeepMemoizedObject.mjs +142 -85
  58. package/dist/esm/useDeepMemoizedObject.mjs.map +1 -1
  59. package/dist/esm/useDeepMemoizedObject.native.js +165 -101
  60. package/dist/esm/useDeepMemoizedObject.native.js.map +1 -1
  61. package/dist/esm/useDeepMemoizedObject.test.mjs +267 -197
  62. package/dist/esm/useDeepMemoizedObject.test.mjs.map +1 -1
  63. package/dist/esm/useDeepMemoizedObject.test.native.js +263 -200
  64. package/dist/esm/useDeepMemoizedObject.test.native.js.map +1 -1
  65. package/dist/esm/useDeferredBoolean.mjs +8 -5
  66. package/dist/esm/useDeferredBoolean.mjs.map +1 -1
  67. package/dist/esm/useDeferredBoolean.native.js +8 -5
  68. package/dist/esm/useDeferredBoolean.native.js.map +1 -1
  69. package/dist/esm/useEffectOnceGlobally.mjs +12 -2
  70. package/dist/esm/useEffectOnceGlobally.mjs.map +1 -1
  71. package/dist/esm/useEffectOnceGlobally.native.js +13 -3
  72. package/dist/esm/useEffectOnceGlobally.native.js.map +1 -1
  73. package/dist/esm/useEvent.mjs +2 -1
  74. package/dist/esm/useEvent.mjs.map +1 -1
  75. package/dist/esm/useEvent.native.js +5 -2
  76. package/dist/esm/useEvent.native.js.map +1 -1
  77. package/dist/esm/useIsMounted.mjs +5 -4
  78. package/dist/esm/useIsMounted.mjs.map +1 -1
  79. package/dist/esm/useIsMounted.native.js +5 -4
  80. package/dist/esm/useIsMounted.native.js.map +1 -1
  81. package/dist/esm/useLastValue.mjs +1 -1
  82. package/dist/esm/useLastValue.mjs.map +1 -1
  83. package/dist/esm/useLastValue.native.js +1 -1
  84. package/dist/esm/useLastValue.native.js.map +1 -1
  85. package/dist/esm/useLastValueIf.mjs +9 -4
  86. package/dist/esm/useLastValueIf.mjs.map +1 -1
  87. package/dist/esm/useLastValueIf.native.js +9 -4
  88. package/dist/esm/useLastValueIf.native.js.map +1 -1
  89. package/dist/esm/useMemoStable.mjs +3 -2
  90. package/dist/esm/useMemoStable.mjs.map +1 -1
  91. package/dist/esm/useMemoStable.native.js +3 -2
  92. package/dist/esm/useMemoStable.native.js.map +1 -1
  93. package/dist/esm/useMemoizedObjectList.mjs +31 -17
  94. package/dist/esm/useMemoizedObjectList.mjs.map +1 -1
  95. package/dist/esm/useMemoizedObjectList.native.js +46 -27
  96. package/dist/esm/useMemoizedObjectList.native.js.map +1 -1
  97. package/dist/esm/useThrottle.mjs +20 -9
  98. package/dist/esm/useThrottle.mjs.map +1 -1
  99. package/dist/esm/useThrottle.native.js +24 -12
  100. package/dist/esm/useThrottle.native.js.map +1 -1
  101. package/dist/esm/useWarnIfDepsChange.mjs +24 -15
  102. package/dist/esm/useWarnIfDepsChange.mjs.map +1 -1
  103. package/dist/esm/useWarnIfDepsChange.native.js +24 -16
  104. package/dist/esm/useWarnIfDepsChange.native.js.map +1 -1
  105. package/dist/esm/useWarnIfMemoChangesOften.mjs +10 -3
  106. package/dist/esm/useWarnIfMemoChangesOften.mjs.map +1 -1
  107. package/dist/esm/useWarnIfMemoChangesOften.native.js +10 -6
  108. package/dist/esm/useWarnIfMemoChangesOften.native.js.map +1 -1
  109. 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
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: !0
9
- });
10
- },
11
- __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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
- return to;
17
- };
17
+ }
18
+ return to;
19
+ };
18
20
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
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 !1;
32
+ if (!immutableToNestedChanges) return false;
31
33
  const currentPath = path.join(".");
32
- for (const pattern in immutableToNestedChanges) if (immutableToNestedChanges[pattern] && currentPath === pattern) return !0;
33
- return !1;
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 (!(typeof target != "object" || target === null || typeof source != "object" || source === null)) {
37
- if (Array.isArray(target) && Array.isArray(source)) {
38
- target.length = 0, target.push(...source);
39
- return;
40
- }
41
- for (const key in source) {
42
- const targetValue = target[key],
43
- sourceValue = source[key];
44
- typeof sourceValue == "object" && sourceValue !== null && typeof targetValue == "object" && targetValue !== null ? deepMutateInPlace(targetValue, sourceValue) : target[key] = sourceValue;
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 = !1) {
49
- if (current === previous) return {
50
- value: previous,
51
- hasChanges: !1,
52
- hasImmutableMutation: !1
53
- };
54
- if (typeof current != "object" || current === null) return {
55
- value: current,
56
- hasChanges: !0,
57
- hasImmutableMutation: !1
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: !0,
69
- hasImmutableMutation: !1
73
+ hasChanges: true,
74
+ hasImmutableMutation: false
70
75
  };
71
- if (current.length !== previous.length) return {
76
+ }
77
+ if (typeof previous !== "object" || previous === null) {
78
+ return {
72
79
  value: current,
73
- hasChanges: !0,
74
- hasImmutableMutation: !1
80
+ hasChanges: true,
81
+ hasImmutableMutation: false
75
82
  };
76
- let hasChanges2 = !1,
77
- hasImmutableMutation2 = !1;
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
- result = deepMemoizeWithTracking(current[i], previous[i], itemPath, immutableToNestedChanges, !1);
82
- memoizedArray[i] = result.value, result.hasChanges && (hasChanges2 = !0), result.hasImmutableMutation && (hasImmutableMutation2 = !0);
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 hasChanges2 || hasImmutableMutation2 ? {
85
- value: memoizedArray,
86
- hasChanges: !0,
87
- hasImmutableMutation: !1
88
- } : {
122
+ return {
89
123
  value: previous,
90
- hasChanges: !1,
91
- hasImmutableMutation: !1
124
+ hasChanges: false,
125
+ hasImmutableMutation: false
92
126
  };
93
127
  }
94
- const currentKeys = Object.keys(current),
95
- previousKeys = Object.keys(previous);
96
- if (currentKeys.length !== previousKeys.length) return {
97
- value: current,
98
- hasChanges: !0,
99
- hasImmutableMutation: !1
100
- };
101
- if (!currentKeys.every(key => key in previous)) return {
102
- value: current,
103
- hasChanges: !0,
104
- hasImmutableMutation: !1
105
- };
106
- let hasChanges = !1,
107
- hasImmutableMutation = !1;
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
- currentValue = current[key],
112
- previousValue = previous[key],
113
- result = deepMemoizeWithTracking(currentValue, previousValue, propPath, immutableToNestedChanges, shouldMutateInPlace);
114
- memoizedObject[key] = result.value, result.hasChanges && (hasChanges = !0), result.hasImmutableMutation && (hasImmutableMutation = !0);
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) deepMutateInPlace(previous, current);else for (const key of currentKeys) previous[key] = memoizedObject[key];
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: !1,
121
- hasImmutableMutation: !0
172
+ hasChanges: false,
173
+ hasImmutableMutation: true
122
174
  };
123
175
  }
124
- return hasChanges || hasImmutableMutation ? {
125
- value: memoizedObject,
126
- hasChanges: !0,
127
- hasImmutableMutation: !1
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: !1,
131
- hasImmutableMutation: !1
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, !1);
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)) return [...result.value];
138
- if (typeof result.value == "object" && result.value !== null) return {
139
- ...result.value
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
- memoizedValue = deepMemoize(value, previousValueRef.current, [], options?.immutableToNestedChanges);
147
- return previousValueRef.current = memoizedValue, memoizedValue;
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
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: !0
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 < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
36
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
35
37
  }
36
38
  function shouldBeImmutable(path, immutableToNestedChanges) {
37
- if (!immutableToNestedChanges) return !1;
39
+ if (!immutableToNestedChanges) return false;
38
40
  var currentPath = path.join(".");
39
- for (var pattern in immutableToNestedChanges) if (immutableToNestedChanges[pattern] && currentPath === pattern) return !0;
40
- return !1;
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 (!((typeof target > "u" ? "undefined" : _type_of(target)) !== "object" || target === null || (typeof source > "u" ? "undefined" : _type_of(source)) !== "object" || source === null)) {
44
- if (Array.isArray(target) && Array.isArray(source)) {
45
- target.length = 0, target.push(...source);
46
- return;
47
- }
48
- for (var key in source) {
49
- var targetValue = target[key],
50
- sourceValue = source[key];
51
- (typeof sourceValue > "u" ? "undefined" : _type_of(sourceValue)) === "object" && sourceValue !== null && (typeof targetValue > "u" ? "undefined" : _type_of(targetValue)) === "object" && targetValue !== null ? deepMutateInPlace(targetValue, sourceValue) : target[key] = sourceValue;
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] : !1;
57
- if (current === previous) return {
58
- value: previous,
59
- hasChanges: !1,
60
- hasImmutableMutation: !1
61
- };
62
- if ((typeof current > "u" ? "undefined" : _type_of(current)) !== "object" || current === null) return {
63
- value: current,
64
- hasChanges: !0,
65
- hasImmutableMutation: !1
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: !0,
78
- hasImmutableMutation: !1
81
+ hasChanges: true,
82
+ hasImmutableMutation: false
79
83
  };
80
- if (current.length !== previous.length) return {
84
+ }
85
+ if ((typeof previous === "undefined" ? "undefined" : _type_of(previous)) !== "object" || previous === null) {
86
+ return {
81
87
  value: current,
82
- hasChanges: !0,
83
- hasImmutableMutation: !1
88
+ hasChanges: true,
89
+ hasImmutableMutation: false
84
90
  };
85
- for (var hasChanges = !1, hasImmutableMutation = !1, memoizedArray = [], i = 0; i < current.length; i++) {
86
- var itemPath = [...path, String(i)],
87
- result = deepMemoizeWithTracking(current[i], previous[i], itemPath, immutableToNestedChanges, !1);
88
- memoizedArray[i] = result.value, result.hasChanges && (hasChanges = !0), result.hasImmutableMutation && (hasImmutableMutation = !0);
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
- return hasChanges || hasImmutableMutation ? {
91
- value: memoizedArray,
92
- hasChanges: !0,
93
- hasImmutableMutation: !1
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: !1,
97
- hasImmutableMutation: !1
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) return {
111
- value: current,
112
- hasChanges: !0,
113
- hasImmutableMutation: !1
114
- };
115
- var hasChanges1 = !1,
116
- hasImmutableMutation1 = !1,
117
- memoizedObject = {},
118
- _iteratorNormalCompletion = !0,
119
- _didIteratorError = !1,
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 = !0) {
123
- var key = _step.value,
124
- propPath = [...path, key],
125
- currentValue = current[key],
126
- previousValue = previous[key],
127
- result1 = deepMemoizeWithTracking(currentValue, previousValue, propPath, immutableToNestedChanges, shouldMutateInPlace);
128
- memoizedObject[key] = result1.value, result1.hasChanges && (hasChanges1 = !0), result1.hasImmutableMutation && (hasImmutableMutation1 = !0);
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 = !0, _iteratorError = err;
177
+ _didIteratorError = true;
178
+ _iteratorError = err;
132
179
  } finally {
133
180
  try {
134
- !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
181
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
182
+ _iterator.return();
183
+ }
135
184
  } finally {
136
- if (_didIteratorError) throw _iteratorError;
185
+ if (_didIteratorError) {
186
+ throw _iteratorError;
187
+ }
137
188
  }
138
189
  }
139
190
  if (shouldMutateInPlace && (hasChanges1 || hasImmutableMutation1)) {
140
- if (parentIsImmutable) deepMutateInPlace(previous, current);else {
141
- var _iteratorNormalCompletion1 = !0,
142
- _didIteratorError1 = !1,
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 = !0) {
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 = !0, _iteratorError1 = err;
204
+ _didIteratorError1 = true;
205
+ _iteratorError1 = err;
151
206
  } finally {
152
207
  try {
153
- !_iteratorNormalCompletion1 && _iterator1.return != null && _iterator1.return();
208
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
209
+ _iterator1.return();
210
+ }
154
211
  } finally {
155
- if (_didIteratorError1) throw _iteratorError1;
212
+ if (_didIteratorError1) {
213
+ throw _iteratorError1;
214
+ }
156
215
  }
157
216
  }
158
217
  }
159
218
  return {
160
219
  value: previous,
161
- hasChanges: !1,
162
- hasImmutableMutation: !0
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 hasChanges1 || hasImmutableMutation1 ? {
166
- value: memoizedObject,
167
- hasChanges: !0,
168
- hasImmutableMutation: !1
169
- } : {
231
+ return {
170
232
  value: previous,
171
- hasChanges: !1,
172
- hasImmutableMutation: !1
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
- result = deepMemoizeWithTracking(current, previous, path, immutableToNestedChanges, !1);
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)) return [...result.value];
181
- if (_type_of(result.value) === "object" && result.value !== null) return {
182
- ...result.value
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
- memoizedValue = deepMemoize(value, previousValueRef.current, [], options?.immutableToNestedChanges);
190
- return previousValueRef.current = memoizedValue, memoizedValue;
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