diff --git a/lib/Onyx.ts b/lib/Onyx.ts index a20cd32f..bee77736 100644 --- a/lib/Onyx.ts +++ b/lib/Onyx.ts @@ -122,8 +122,13 @@ function connect(connectOptions: ConnectOptions): nu // We search all the keys in storage to see if any are a "match" for the subscriber we are connecting so that we // can send data back to the subscriber. Note that multiple keys can match as a subscriber could either be // subscribed to a "collection key" or a single key. - const matchingKeys = Array.from(keys).filter((key) => OnyxUtils.isKeyMatch(mapping.key, key)); - + const matchingKeys: string[] = []; + keys.forEach((key) => { + if (!OnyxUtils.isKeyMatch(mapping.key, key)) { + return; + } + matchingKeys.push(key); + }); // If the key being connected to does not exist we initialize the value with null. For subscribers that connected // directly via connect() they will simply get a null value sent to them without any information about which key matched // since there are none matched. In withOnyx() we wait for all connected keys to return a value before rendering the child diff --git a/lib/OnyxUtils.ts b/lib/OnyxUtils.ts index 9c21a532..13f5fb18 100644 --- a/lib/OnyxUtils.ts +++ b/lib/OnyxUtils.ts @@ -327,17 +327,14 @@ function tryGetCachedValue(key: TKey, mapping?: Partial k.startsWith(key)); - const values = matchingKeys.reduce((finalObject: NonNullable>, matchedKey) => { - const cachedValue = cache.get(matchedKey); - if (cachedValue) { - // This is permissible because we're in the process of constructing the final object in a reduce function. - // eslint-disable-next-line no-param-reassign - finalObject[matchedKey] = cachedValue; + const values: OnyxCollection = {}; + allCacheKeys.forEach((cacheKey) => { + if (!cacheKey.startsWith(key)) { + return; } - return finalObject; - }, {}); + values[cacheKey] = cache.get(cacheKey); + }); val = values; }