react-native-onyx 2.0.95 → 2.0.96
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/README.md +2 -2
- package/dist/OnyxConnectionManager.js +10 -3
- package/dist/OnyxUtils.js +2 -2
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -331,11 +331,11 @@ This will fire the callback once per member key depending on how many collection
|
|
|
331
331
|
Onyx.connect({
|
|
332
332
|
key: ONYXKEYS.COLLECTION.REPORT,
|
|
333
333
|
waitForCollectionCallback: true,
|
|
334
|
-
callback: (allReports) => {...},
|
|
334
|
+
callback: (allReports, collectionKey, sourceValue) => {...},
|
|
335
335
|
});
|
|
336
336
|
```
|
|
337
337
|
|
|
338
|
-
This final option forces `Onyx.connect()` to behave more like `useOnyx()` and only update the callback once with the entire collection initially and later with an updated version of the collection when individual keys update.
|
|
338
|
+
This final option forces `Onyx.connect()` to behave more like `useOnyx()` and only update the callback once with the entire collection initially and later with an updated version of the collection when individual keys update. The `sourceValue` parameter contains only the specific keys and values that triggered the current update, which can be useful for optimizing your code to only process what changed. This parameter is not available when `waitForCollectionCallback` is false or the key is not a collection key.
|
|
339
339
|
|
|
340
340
|
### Performance Considerations When Using Collections
|
|
341
341
|
|
|
@@ -73,7 +73,12 @@ class OnyxConnectionManager {
|
|
|
73
73
|
fireCallbacks(connectionID) {
|
|
74
74
|
const connection = this.connectionsMap.get(connectionID);
|
|
75
75
|
connection === null || connection === void 0 ? void 0 : connection.callbacks.forEach((callback) => {
|
|
76
|
-
|
|
76
|
+
if (connection.waitForCollectionCallback) {
|
|
77
|
+
callback(connection.cachedCallbackValue, connection.cachedCallbackKey, connection.sourceValue);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
callback(connection.cachedCallbackValue, connection.cachedCallbackKey);
|
|
81
|
+
}
|
|
77
82
|
});
|
|
78
83
|
}
|
|
79
84
|
/**
|
|
@@ -93,7 +98,7 @@ class OnyxConnectionManager {
|
|
|
93
98
|
// If the subscriber is a `withOnyx` HOC we don't define `callback` as the HOC will use
|
|
94
99
|
// its own logic to handle the data.
|
|
95
100
|
if (!utils_1.default.hasWithOnyxInstance(connectOptions)) {
|
|
96
|
-
callback = (value, key) => {
|
|
101
|
+
callback = (value, key, sourceValue) => {
|
|
97
102
|
const createdConnection = this.connectionsMap.get(connectionID);
|
|
98
103
|
if (createdConnection) {
|
|
99
104
|
// We signal that the first connection was made and now any new subscribers
|
|
@@ -101,16 +106,18 @@ class OnyxConnectionManager {
|
|
|
101
106
|
createdConnection.isConnectionMade = true;
|
|
102
107
|
createdConnection.cachedCallbackValue = value;
|
|
103
108
|
createdConnection.cachedCallbackKey = key;
|
|
109
|
+
createdConnection.sourceValue = sourceValue;
|
|
104
110
|
this.fireCallbacks(connectionID);
|
|
105
111
|
}
|
|
106
112
|
};
|
|
107
113
|
}
|
|
108
|
-
subscriptionID = OnyxUtils_1.default.subscribeToKey(Object.assign(Object.assign({}, connectOptions), { callback }));
|
|
114
|
+
subscriptionID = OnyxUtils_1.default.subscribeToKey(Object.assign(Object.assign({}, connectOptions), { callback: callback }));
|
|
109
115
|
connectionMetadata = {
|
|
110
116
|
subscriptionID,
|
|
111
117
|
onyxKey: connectOptions.key,
|
|
112
118
|
isConnectionMade: false,
|
|
113
119
|
callbacks: new Map(),
|
|
120
|
+
waitForCollectionCallback: connectOptions.waitForCollectionCallback,
|
|
114
121
|
};
|
|
115
122
|
this.connectionsMap.set(connectionID, connectionMetadata);
|
|
116
123
|
}
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -562,7 +562,7 @@ function keysChanged(collectionKey, partialCollection, partialPreviousCollection
|
|
|
562
562
|
// send the whole cached collection.
|
|
563
563
|
if (isSubscribedToCollectionKey) {
|
|
564
564
|
if (subscriber.waitForCollectionCallback) {
|
|
565
|
-
subscriber.callback(cachedCollection, subscriber.key);
|
|
565
|
+
subscriber.callback(cachedCollection, subscriber.key, partialCollection);
|
|
566
566
|
continue;
|
|
567
567
|
}
|
|
568
568
|
// If they are not using waitForCollectionCallback then we notify the subscriber with
|
|
@@ -738,7 +738,7 @@ function keyChanged(key, value, previousValue, canUpdateSubscriber = () => true,
|
|
|
738
738
|
cachedCollections[subscriber.key] = cachedCollection;
|
|
739
739
|
}
|
|
740
740
|
cachedCollection[key] = value;
|
|
741
|
-
subscriber.callback(cachedCollection, subscriber.key);
|
|
741
|
+
subscriber.callback(cachedCollection, subscriber.key, { [key]: value });
|
|
742
742
|
continue;
|
|
743
743
|
}
|
|
744
744
|
const subscriberCallback = subscriber.callback;
|
package/dist/types.d.ts
CHANGED
|
@@ -238,7 +238,7 @@ type BaseConnectOptions = {
|
|
|
238
238
|
/** Represents the callback function used in `Onyx.connect()` method with a regular key. */
|
|
239
239
|
type DefaultConnectCallback<TKey extends OnyxKey> = (value: OnyxEntry<KeyValueMapping[TKey]>, key: TKey) => void;
|
|
240
240
|
/** Represents the callback function used in `Onyx.connect()` method with a collection key. */
|
|
241
|
-
type CollectionConnectCallback<TKey extends OnyxKey> = (value: NonUndefined<OnyxCollection<KeyValueMapping[TKey]>>, key: TKey) => void;
|
|
241
|
+
type CollectionConnectCallback<TKey extends OnyxKey> = (value: NonUndefined<OnyxCollection<KeyValueMapping[TKey]>>, key: TKey, sourceValue?: OnyxValue<TKey>) => void;
|
|
242
242
|
/** Represents the options used in `Onyx.connect()` method with a regular key. */
|
|
243
243
|
type DefaultConnectOptions<TKey extends OnyxKey> = BaseConnectOptions & {
|
|
244
244
|
/** The Onyx key to subscribe to. */
|