react-native-onyx 2.0.69 → 2.0.71

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.
@@ -48,16 +48,21 @@ class OnyxConnectionManager {
48
48
  * according to their purpose and effect they produce in the Onyx connection.
49
49
  */
50
50
  generateConnectionID(connectOptions) {
51
- var _a, _b;
51
+ const { key, initWithStoredValues, reuseConnection, waitForCollectionCallback } = connectOptions;
52
52
  let suffix = '';
53
53
  // We will generate a unique ID in any of the following situations:
54
- // - `connectOptions.reuseConnection` is `false`. That means the subscriber explicitly wants the connection to not be reused.
55
- // - `connectOptions.initWithStoredValues` is `false`. This flag changes the subscription flow when set to `false`, so the connection can't be reused.
54
+ // - `reuseConnection` is `false`. That means the subscriber explicitly wants the connection to not be reused.
55
+ // - `initWithStoredValues` is `false`. This flag changes the subscription flow when set to `false`, so the connection can't be reused.
56
+ // - `key` is a collection key AND `waitForCollectionCallback` is `undefined/false`. This combination needs a new connection at every subscription
57
+ // in order to send all the collection entries, so the connection can't be reused.
56
58
  // - `withOnyxInstance` is defined inside `connectOptions`. That means the subscriber is a `withOnyx` HOC and therefore doesn't support connection reuse.
57
- if (connectOptions.reuseConnection === false || connectOptions.initWithStoredValues === false || utils_1.default.hasWithOnyxInstance(connectOptions)) {
59
+ if (reuseConnection === false ||
60
+ initWithStoredValues === false ||
61
+ (!utils_1.default.hasWithOnyxInstance(connectOptions) && OnyxUtils_1.default.isCollectionKey(key) && (waitForCollectionCallback === undefined || waitForCollectionCallback === false)) ||
62
+ utils_1.default.hasWithOnyxInstance(connectOptions)) {
58
63
  suffix += `,uniqueID=${Str.guid()}`;
59
64
  }
60
- return `onyxKey=${connectOptions.key},initWithStoredValues=${(_a = connectOptions.initWithStoredValues) !== null && _a !== void 0 ? _a : true},waitForCollectionCallback=${(_b = connectOptions.waitForCollectionCallback) !== null && _b !== void 0 ? _b : false}${suffix}`;
65
+ return `onyxKey=${key},initWithStoredValues=${initWithStoredValues !== null && initWithStoredValues !== void 0 ? initWithStoredValues : true},waitForCollectionCallback=${waitForCollectionCallback !== null && waitForCollectionCallback !== void 0 ? waitForCollectionCallback : false}${suffix}`;
61
66
  }
62
67
  /**
63
68
  * Fires all the subscribers callbacks associated with that connection ID.
package/dist/useOnyx.js CHANGED
@@ -26,7 +26,7 @@ function useOnyx(key, options) {
26
26
  const newValueRef = (0, react_1.useRef)(null);
27
27
  // Stores the previously result returned by the hook, containing the data from cache and the fetch status.
28
28
  // We initialize it to `undefined` and `loading` fetch status to simulate the initial result when the hook is loading from the cache.
29
- // However, if `initWithStoredValues` is `true` we set the fetch status to `loaded` since we want to signal that data is ready.
29
+ // However, if `initWithStoredValues` is `false` we set the fetch status to `loaded` since we want to signal that data is ready.
30
30
  const resultRef = (0, react_1.useRef)([
31
31
  undefined,
32
32
  {
@@ -74,6 +74,10 @@ function useOnyx(key, options) {
74
74
  }, [key, options === null || options === void 0 ? void 0 : options.canEvict]);
75
75
  const getSnapshot = (0, react_1.useCallback)(() => {
76
76
  var _a, _b, _c;
77
+ // We return the initial result right away during the first connection if `initWithStoredValues` is set to `false`.
78
+ if (isFirstConnectionRef.current && (options === null || options === void 0 ? void 0 : options.initWithStoredValues) === false) {
79
+ return resultRef.current;
80
+ }
77
81
  // We get the value from cache while the first connection to Onyx is being made,
78
82
  // so we can return any cached value right away. After the connection is made, we only
79
83
  // update `newValueRef` when `Onyx.connect()` callback is fired.
@@ -123,7 +127,7 @@ function useOnyx(key, options) {
123
127
  resultRef.current = [previousValueRef.current, { status: newFetchStatus !== null && newFetchStatus !== void 0 ? newFetchStatus : 'loaded' }];
124
128
  }
125
129
  return resultRef.current;
126
- }, [key, selectorRef, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.initialValue]);
130
+ }, [key, selectorRef, options === null || options === void 0 ? void 0 : options.initWithStoredValues, options === null || options === void 0 ? void 0 : options.allowStaleData, options === null || options === void 0 ? void 0 : options.initialValue]);
127
131
  const subscribe = (0, react_1.useCallback)((onStoreChange) => {
128
132
  connectionRef.current = OnyxConnectionManager_1.default.connect({
129
133
  key,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "2.0.69",
3
+ "version": "2.0.71",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",