react-native-onyx 2.0.134 → 2.0.135
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/OnyxUtils.d.ts +2 -2
- package/dist/OnyxUtils.js +10 -8
- package/dist/types.d.ts +2 -0
- package/dist/useOnyx.js +1 -0
- package/package.json +1 -1
package/dist/OnyxUtils.d.ts
CHANGED
|
@@ -143,14 +143,14 @@ declare function getCachedCollection<TKey extends CollectionKeyBase>(collectionK
|
|
|
143
143
|
/**
|
|
144
144
|
* When a collection of keys change, search for any callbacks matching the collection key and trigger those callbacks
|
|
145
145
|
*/
|
|
146
|
-
declare function keysChanged<TKey extends CollectionKeyBase>(collectionKey: TKey, partialCollection: OnyxCollection<KeyValueMapping[TKey]>, partialPreviousCollection: OnyxCollection<KeyValueMapping[TKey]> | undefined, notifyConnectSubscribers?: boolean, notifyWithOnyxSubscribers?: boolean): void;
|
|
146
|
+
declare function keysChanged<TKey extends CollectionKeyBase>(collectionKey: TKey, partialCollection: OnyxCollection<KeyValueMapping[TKey]>, partialPreviousCollection: OnyxCollection<KeyValueMapping[TKey]> | undefined, notifyConnectSubscribers?: boolean, notifyWithOnyxSubscribers?: boolean, notifyUseOnyxHookSubscribers?: boolean): void;
|
|
147
147
|
/**
|
|
148
148
|
* When a key change happens, search for any callbacks matching the key or collection key and trigger those callbacks
|
|
149
149
|
*
|
|
150
150
|
* @example
|
|
151
151
|
* keyChanged(key, value, subscriber => subscriber.initWithStoredValues === false)
|
|
152
152
|
*/
|
|
153
|
-
declare function keyChanged<TKey extends OnyxKey>(key: TKey, value: OnyxValue<TKey>, previousValue: OnyxValue<TKey>, canUpdateSubscriber?: (subscriber?: Mapping<OnyxKey>) => boolean, notifyConnectSubscribers?: boolean, notifyWithOnyxSubscribers?: boolean): void;
|
|
153
|
+
declare function keyChanged<TKey extends OnyxKey>(key: TKey, value: OnyxValue<TKey>, previousValue: OnyxValue<TKey>, canUpdateSubscriber?: (subscriber?: Mapping<OnyxKey>) => boolean, notifyConnectSubscribers?: boolean, notifyWithOnyxSubscribers?: boolean, notifyUseOnyxHookSubscribers?: boolean): void;
|
|
154
154
|
/**
|
|
155
155
|
* Sends the data obtained from the keys to the connection. It either:
|
|
156
156
|
* - sets state on the withOnyxInstances
|
package/dist/OnyxUtils.js
CHANGED
|
@@ -512,7 +512,7 @@ function getCachedCollection(collectionKey, collectionMemberKeys) {
|
|
|
512
512
|
/**
|
|
513
513
|
* When a collection of keys change, search for any callbacks matching the collection key and trigger those callbacks
|
|
514
514
|
*/
|
|
515
|
-
function keysChanged(collectionKey, partialCollection, partialPreviousCollection, notifyConnectSubscribers = true, notifyWithOnyxSubscribers = true) {
|
|
515
|
+
function keysChanged(collectionKey, partialCollection, partialPreviousCollection, notifyConnectSubscribers = true, notifyWithOnyxSubscribers = true, notifyUseOnyxHookSubscribers = true) {
|
|
516
516
|
// We prepare the "cached collection" which is the entire collection + the new partial data that
|
|
517
517
|
// was merged in via mergeCollection().
|
|
518
518
|
const cachedCollection = getCachedCollection(collectionKey);
|
|
@@ -540,7 +540,8 @@ function keysChanged(collectionKey, partialCollection, partialPreviousCollection
|
|
|
540
540
|
const isSubscribedToCollectionMemberKey = isCollectionMemberKey(collectionKey, subscriber.key);
|
|
541
541
|
// Regular Onyx.connect() subscriber found.
|
|
542
542
|
if (typeof subscriber.callback === 'function') {
|
|
543
|
-
if (
|
|
543
|
+
// Check if it's a useOnyx or a regular Onyx.connect() subscriber
|
|
544
|
+
if ((subscriber.isUseOnyxSubscriber && !notifyUseOnyxHookSubscribers) || (!subscriber.isUseOnyxSubscriber && !notifyConnectSubscribers)) {
|
|
544
545
|
continue;
|
|
545
546
|
}
|
|
546
547
|
// If they are subscribed to the collection key and using waitForCollectionCallback then we'll
|
|
@@ -670,7 +671,7 @@ function keysChanged(collectionKey, partialCollection, partialPreviousCollection
|
|
|
670
671
|
* @example
|
|
671
672
|
* keyChanged(key, value, subscriber => subscriber.initWithStoredValues === false)
|
|
672
673
|
*/
|
|
673
|
-
function keyChanged(key, value, previousValue, canUpdateSubscriber = () => true, notifyConnectSubscribers = true, notifyWithOnyxSubscribers = true) {
|
|
674
|
+
function keyChanged(key, value, previousValue, canUpdateSubscriber = () => true, notifyConnectSubscribers = true, notifyWithOnyxSubscribers = true, notifyUseOnyxHookSubscribers = true) {
|
|
674
675
|
var _a, _b;
|
|
675
676
|
// Add or remove this key from the recentlyAccessedKeys lists
|
|
676
677
|
if (value !== null) {
|
|
@@ -709,7 +710,8 @@ function keyChanged(key, value, previousValue, canUpdateSubscriber = () => true,
|
|
|
709
710
|
}
|
|
710
711
|
// Subscriber is a regular call to connect() and provided a callback
|
|
711
712
|
if (typeof subscriber.callback === 'function') {
|
|
712
|
-
if (
|
|
713
|
+
// Check if it's a useOnyx or a regular Onyx.connect() subscriber
|
|
714
|
+
if ((subscriber.isUseOnyxSubscriber && !notifyUseOnyxHookSubscribers) || (!subscriber.isUseOnyxSubscriber && !notifyConnectSubscribers)) {
|
|
713
715
|
continue;
|
|
714
716
|
}
|
|
715
717
|
if (lastConnectionCallbackData.has(subscriber.subscriptionID) && lastConnectionCallbackData.get(subscriber.subscriptionID) === value) {
|
|
@@ -889,8 +891,8 @@ function getCollectionDataAndSendAsObject(matchingKeys, mapping) {
|
|
|
889
891
|
* scheduleSubscriberUpdate(key, value, subscriber => subscriber.initWithStoredValues === false)
|
|
890
892
|
*/
|
|
891
893
|
function scheduleSubscriberUpdate(key, value, previousValue, canUpdateSubscriber = () => true) {
|
|
892
|
-
const promise = Promise.resolve().then(() => keyChanged(key, value, previousValue, canUpdateSubscriber, true, false));
|
|
893
|
-
batchUpdates(() => keyChanged(key, value, previousValue, canUpdateSubscriber, false, true));
|
|
894
|
+
const promise = Promise.resolve().then(() => keyChanged(key, value, previousValue, canUpdateSubscriber, true, false, false));
|
|
895
|
+
batchUpdates(() => keyChanged(key, value, previousValue, canUpdateSubscriber, false, true, true));
|
|
894
896
|
return Promise.all([maybeFlushBatchUpdates(), promise]).then(() => undefined);
|
|
895
897
|
}
|
|
896
898
|
/**
|
|
@@ -899,8 +901,8 @@ function scheduleSubscriberUpdate(key, value, previousValue, canUpdateSubscriber
|
|
|
899
901
|
* subscriber callbacks receive the data in a different format than they normally expect and it breaks code.
|
|
900
902
|
*/
|
|
901
903
|
function scheduleNotifyCollectionSubscribers(key, value, previousValue) {
|
|
902
|
-
const promise = Promise.resolve().then(() => keysChanged(key, value, previousValue, true, false));
|
|
903
|
-
batchUpdates(() => keysChanged(key, value, previousValue, false, true));
|
|
904
|
+
const promise = Promise.resolve().then(() => keysChanged(key, value, previousValue, true, false, false));
|
|
905
|
+
batchUpdates(() => keysChanged(key, value, previousValue, false, true, true));
|
|
904
906
|
return Promise.all([maybeFlushBatchUpdates(), promise]).then(() => undefined);
|
|
905
907
|
}
|
|
906
908
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -235,6 +235,8 @@ type BaseConnectOptions = {
|
|
|
235
235
|
* with the same connect configurations.
|
|
236
236
|
*/
|
|
237
237
|
reuseConnection?: boolean;
|
|
238
|
+
/** Indicates whether this subscriber is created from the useOnyx hook. */
|
|
239
|
+
isUseOnyxSubscriber?: boolean;
|
|
238
240
|
};
|
|
239
241
|
/** Represents the callback function used in `Onyx.connect()` method with a regular key. */
|
|
240
242
|
type DefaultConnectCallback<TKey extends OnyxKey> = (value: OnyxEntry<KeyValueMapping[TKey]>, key: TKey) => void;
|
package/dist/useOnyx.js
CHANGED
|
@@ -249,6 +249,7 @@ function useOnyx(key, options, dependencies = []) {
|
|
|
249
249
|
initWithStoredValues: options === null || options === void 0 ? void 0 : options.initWithStoredValues,
|
|
250
250
|
waitForCollectionCallback: OnyxUtils_1.default.isCollectionKey(key),
|
|
251
251
|
reuseConnection: options === null || options === void 0 ? void 0 : options.reuseConnection,
|
|
252
|
+
isUseOnyxSubscriber: true,
|
|
252
253
|
});
|
|
253
254
|
checkEvictableKey();
|
|
254
255
|
return () => {
|