-
Notifications
You must be signed in to change notification settings - Fork 73
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
Add multiSet to update #305
Conversation
db902e3
to
0c35c72
Compare
0c35c72
to
8857a33
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes looks good. Maybe a good follow up eventually is to update the multiSet()
logic so that it can group which of the keys belong to a collection and then update subscribers in a more optimized way.
Lines 985 to 992 in f96fa2d
_.each(data, (val, key) => { | |
// Update cache and optimistically inform subscribers on the next tick | |
cache.set(key, val); | |
notifySubscribersOnNextTick(key, val); | |
}); | |
return Storage.multiSet(keyValuePairs) | |
.catch(error => evictStorageAndRetry(error, multiSet, data)); |
That might bite us in the future (sudden bad performance) if someone tries to use multiSet()
to update a collection and also when there is a subscriber for the collection key.
lib/Onyx.js
Outdated
} | ||
|
||
throw new Error(`Invalid ${typeof key} key provided in Onyx multiSet. Onyx key must be of type string.`); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems not logically possible because all keys of an object must be strings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can be other types as well. At least, what I'm looking to do if prevent number-type keys at the very minimum. You can see this in my unit test.: https://github.com/Expensify/react-native-onyx/pull/305/files#diff-fb75d1d7a8480f8429b43b89f94665322ee4576f95220815a5f7f3275e99fb40R605
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, not trying to split hairs. I thought they would be cast to string. At least when iterating over them with Object.keys()
, but maybe numbers are unique 🤷♂️
NAB, I am not sure why should we not use a number as a key for Onyx. We would never do it. But doesn't seem like it should be explicitly prevented for any reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nice, okay. I can remove those checks then.
]; | ||
|
||
try { | ||
// When we pass it to Onyx.update | ||
Onyx.update(data); | ||
} catch (error) { | ||
// Then we should expect the error message below | ||
expect(error.message).toEqual('Invalid onyxMethod multiSet in Onyx update.'); | ||
expect(error.message).toEqual('Invalid onyxMethod murge in Onyx update.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
murge?! 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha - yeah open to ideas for better names for a "wrong" onyxMethod.
Yeah I thought about that. Seems like a good issue for a follow-up since there isn't an immediate need for it. |
cf01af9
to
847454d
Compare
LGTM |
Follow-up issue is here: #313 |
@marcaaron please review
Details
Adds
multiset
to onyx's update.Related Issues
https://github.com/Expensify/Expensify/issues/309134
Automated Tests
Added 2 tests
Linked PRs