react-native-onyx 1.0.106 → 1.0.108

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/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 allKeys = cache.getAllKeys();
239
- const matchingKeys = _.filter(allKeys, k => k.startsWith(key));
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
- if (_.isEmpty(values)) {
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/withOnyx.d.ts CHANGED
@@ -7,6 +7,15 @@ import {CollectionKeyBase, KeyValueMapping, OnyxCollection, OnyxEntry, OnyxKey,
7
7
  type BaseMapping<TComponentProps, TOnyxProps> = {
8
8
  canEvict?: boolean | ((props: Omit<TComponentProps, keyof TOnyxProps>) => boolean);
9
9
  initWithStoredValues?: boolean;
10
+ allowStaleData?: boolean;
11
+ };
12
+
13
+ type CollectionBaseMapping<TOnyxKey extends CollectionKeyBase> = {
14
+ initialValue?: OnyxCollection<KeyValueMapping[TOnyxKey]>;
15
+ };
16
+
17
+ type EntryBaseMapping<TOnyxKey extends OnyxKey> = {
18
+ initialValue?: OnyxEntry<KeyValueMapping[TOnyxKey]>;
10
19
  };
11
20
 
12
21
  /**
@@ -99,7 +108,7 @@ type BaseMappingFunctionKeyAndSelector<
99
108
  type Mapping<TComponentProps, TOnyxProps, TOnyxProp extends keyof TOnyxProps, TOnyxKey extends OnyxKey> = BaseMapping<
100
109
  TComponentProps,
101
110
  TOnyxProps
102
- > &
111
+ > & EntryBaseMapping<TOnyxKey> &
103
112
  (
104
113
  | BaseMappingKey<TComponentProps, TOnyxProps, TOnyxProp, TOnyxKey, OnyxEntry<KeyValueMapping[TOnyxKey]>>
105
114
  | BaseMappingStringKeyAndSelector<TComponentProps, TOnyxProps, TOnyxProp, TOnyxKey>
@@ -114,7 +123,7 @@ type CollectionMapping<
114
123
  TOnyxProps,
115
124
  TOnyxProp extends keyof TOnyxProps,
116
125
  TOnyxKey extends CollectionKeyBase
117
- > = BaseMapping<TComponentProps, TOnyxProps> &
126
+ > = BaseMapping<TComponentProps, TOnyxProps> & CollectionBaseMapping<TOnyxKey> &
118
127
  (
119
128
  | BaseMappingKey<TComponentProps, TOnyxProps, TOnyxProp, TOnyxKey, OnyxCollection<KeyValueMapping[TOnyxKey]>>
120
129
  | BaseMappingStringKeyAndSelector<TComponentProps, TOnyxProps, TOnyxProp, TOnyxKey>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "1.0.106",
3
+ "version": "1.0.108",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",