react-native-onyx 1.0.107 → 1.0.109
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/web.development.js +13 -5
- package/dist/web.development.js.map +1 -1
- package/dist/web.min.js +1 -1
- package/dist/web.min.js.map +1 -1
- package/lib/Onyx.js +13 -5
- package/lib/utils.d.ts +14 -0
- package/package.json +1 -1
package/lib/Onyx.js
CHANGED
|
@@ -235,8 +235,14 @@ function tryGetCachedValue(key, mapping = {}) {
|
|
|
235
235
|
let val = cache.getValue(key);
|
|
236
236
|
|
|
237
237
|
if (isCollectionKey(key)) {
|
|
238
|
-
const
|
|
239
|
-
|
|
238
|
+
const allCacheKeys = cache.getAllKeys();
|
|
239
|
+
|
|
240
|
+
// It is possible we haven't loaded all keys yet so we do not know if the
|
|
241
|
+
// collection actually exists.
|
|
242
|
+
if (allCacheKeys.length === 0) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const matchingKeys = _.filter(allCacheKeys, k => k.startsWith(key));
|
|
240
246
|
const values = _.reduce(matchingKeys, (finalObject, matchedKey) => {
|
|
241
247
|
const cachedValue = cache.getValue(matchedKey);
|
|
242
248
|
if (cachedValue) {
|
|
@@ -246,9 +252,7 @@ function tryGetCachedValue(key, mapping = {}) {
|
|
|
246
252
|
}
|
|
247
253
|
return finalObject;
|
|
248
254
|
}, {});
|
|
249
|
-
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
255
|
+
|
|
252
256
|
val = values;
|
|
253
257
|
}
|
|
254
258
|
|
|
@@ -826,6 +830,10 @@ function connect(mapping) {
|
|
|
826
830
|
// since there are none matched. In withOnyx() we wait for all connected keys to return a value before rendering the child
|
|
827
831
|
// component. This null value will be filtered out so that the connected component can utilize defaultProps.
|
|
828
832
|
if (matchingKeys.length === 0) {
|
|
833
|
+
if (mapping.key && !isCollectionKey(mapping.key)) {
|
|
834
|
+
cache.set(mapping.key, null);
|
|
835
|
+
}
|
|
836
|
+
|
|
829
837
|
// Here we cannot use batching because the null value is expected to be set immediately for default props
|
|
830
838
|
// or they will be undefined.
|
|
831
839
|
sendDataToConnection(mapping, null, undefined, false);
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merges two objects and removes null values if "shouldRemoveNullObjectValues" is set to true
|
|
3
|
+
*
|
|
4
|
+
* We generally want to remove null values from objects written to disk and cache, because it decreases the amount of data stored in memory and on disk.
|
|
5
|
+
* On native, when merging an existing value with new changes, SQLite will use JSON_PATCH, which removes top-level nullish values.
|
|
6
|
+
* To be consistent with the behaviour for merge, we'll also want to remove null values for "set" operations.
|
|
7
|
+
*/
|
|
8
|
+
declare function fastMerge<T>(
|
|
9
|
+
target: T,
|
|
10
|
+
source: T,
|
|
11
|
+
shouldRemoveNullObjectValues: boolean = true
|
|
12
|
+
): T;
|
|
13
|
+
|
|
14
|
+
export default { fastMerge };
|