Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a map for Onyx collection keys #330

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ let lastConnectionID = 0;
// Holds a mapping of all the react components that want their state subscribed to a store key
const callbackToStateMapping = {};

// Stores all of the keys that Onyx can use. Must be defined in init().
let onyxKeys = {};
// Keeps a copy of the values of the onyx collection keys as a map for faster lookups
let onyxCollectionKeyMap = new Map();

// Holds a list of keys that have been directly subscribed to or recently modified from least to most recent
let recentlyAccessedKeys = [];
Expand Down Expand Up @@ -141,7 +141,7 @@ function getAllKeys() {
* @returns {Boolean}
*/
function isCollectionKey(key) {
return _.contains(_.values(onyxKeys.COLLECTION), key);
return onyxCollectionKeyMap.has(key);
}

/**
Expand Down Expand Up @@ -1392,8 +1392,13 @@ function init({
cache.setRecentKeysLimit(maxCachedKeysCount);
}

// Let Onyx know about all of our keys
onyxKeys = keys;
// We need the value of the collection keys later for checking if a
// key is a collection. We store it in a map for faster lookup.
const collectionValues = _.values(keys.COLLECTION);
onyxCollectionKeyMap = _.reduce(collectionValues, (acc, val) => {
acc.set(val, true);
return acc;
}, new Map());

// Set our default key states to use when initializing and clearing Onyx data
defaultKeyStates = initialKeyStates;
Expand Down
Loading