Add public Onyx.get - #831
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ef3f683cb7
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 36f7695d07
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
0fa6e3b to
d3e0b52
Compare
Details
Adds
Onyx.get(key), a public one-shot asynchronous read on theOnyxobject, so callers can read a key without opening a subscription.What it does
Onyx.get<TKey>(key: TKey): Promise<OnyxValue<TKey>>(lib/Onyx.ts:632), registered on theOnyxobject (lib/Onyx.ts:663) and therefore reachable through the default export oflib/index.ts.OnyxUtils.afterInit, so a call made beforeOnyx.init()has finished resolves with the hydrated value instead ofundefined.OnyxUtils.get(key)and normalisesnulltoundefined.OnyxUtils.getAllKeys()plusOnyxUtils.multiGet()over the matching member keys, which also warms the cache for the next read.OnyxUtils.getcannot return a whole collection, so that gap is what this function closes.No new storage machinery is introduced; these are the same reads
useOnyxalready performs.Semantics, documented in the JSDoc and in
API.mduseOnyx(). Callers must treat it as read-only: a mutation is visible to every other reader of that key.get()is called is not visible to it, so the write has to be awaited before reading.{}. A collection read on a completely empty store resolves toundefined.useOnyx()orOnyx.connectWithoutView()when the value has to stay current.get()is a point-in-time read.Related Issues
GH_LINK
Linked E/App PR
Expensify/App#99667
Automated Tests
tests/unit/onyxTest.tsgains adescribe('get')block with 14 cases covering:undefinedafterInitpaths: waiting for initialization for a single key and for a collection, resolvingundefinedafter init when the key has no value, and resolving a collection asundefinedon a completely empty storetests/perf-test/Onyx.perf-test.tsgains adescribe('get')block with two benchmarks: 1k reads of a whole 10k-member collection of heavy objects, and 10k reads of individual collection members.API.mdis regenerated from the JSDoc.Manual Tests
This is a library API addition with no UI surface, so it is exercised through the linked E/App PR rather than in isolation:
react-native-onyxto this PR's HEAD.Onyx.getstill load their data.useOnyxfor the same keys.Author Checklist
### Related Issuessection above### Linked E/App PRsection above, and verified this change against it (E/App CI passed and manual testing completed)TestssectiontoggleReportand notonIconClick)myBool && <MyComponent />.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)Avataris modified, I verified thatAvataris working as expected in all cases)mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari