Repository navigation
Add public Onyx.get - mutable #850
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
Merged
chuckdries
merged 10 commits into
Expensify:main
from
callstack-internal:feat/onyx-get-async-mutable
Oct 6, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6edd3fc
Add Onyx.get
LukasMod b3c7815
Add public multiGet
LukasMod da85983
Address review comments
fabioh8010 32497bb
Serve Onyx.get from the cache only
fabioh8010 c89a5d9
Flatten Onyx.multiGet onto one cache read
fabioh8010 b548d5b
Merge remote-tracking branch 'origin/main' into feat/onyx-get-async-m…
fabioh8010 a7df39e
Merge remote-tracking branch 'origin/main' into feat/onyx-get-async-m…
fabioh8010 102a214
Read through OnyxSubscriptionManager.getState after the store flip
fabioh8010 96f8992
Edit a copy in the get type test and drop its exports
LukasMod bf70ff7
Report cache misses where storage still holds the value
LukasMod File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
LukasMod marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import Onyx from '../../dist/Onyx'; | ||
| import ONYX_KEYS from './setup'; | ||
|
|
||
| async function readCollectionMember() { | ||
| const member = await Onyx.get(`${ONYX_KEYS.COLLECTION.TEST_KEY}1`); | ||
|
|
||
| if (!member) { | ||
| return; | ||
| } | ||
|
|
||
| // Annotation pins the draft to the read type because a spread alone drops readonly modifiers. | ||
| const draft: typeof member = {...member, list: member.list ? [...member.list] : undefined}; | ||
| draft.str = 'mutated'; | ||
| draft.list?.push('appended'); | ||
|
|
||
| return draft; | ||
| } | ||
|
|
||
| async function readCollection() { | ||
| const collection = await Onyx.get(ONYX_KEYS.COLLECTION.TEST_KEY); | ||
|
|
||
| if (!collection) { | ||
| return; | ||
| } | ||
|
|
||
| const draft: typeof collection = {...collection}; | ||
| draft.test_1 = {str: 'mutated'}; | ||
|
|
||
| return draft; | ||
| } | ||
|
|
||
| async function writeBackWhatWasRead() { | ||
| const value = await Onyx.get(ONYX_KEYS.TEST_KEY); | ||
| await Onyx.set(ONYX_KEYS.TEST_KEY, value ?? null); | ||
| await Onyx.merge(ONYX_KEYS.TEST_KEY, value ?? null); | ||
|
|
||
| const member = await Onyx.get(`${ONYX_KEYS.COLLECTION.TEST_KEY}1`); | ||
|
|
||
| if (!member) { | ||
| return; | ||
| } | ||
|
|
||
| await Onyx.set(`${ONYX_KEYS.COLLECTION.TEST_KEY}1`, member); | ||
| await Onyx.merge(`${ONYX_KEYS.COLLECTION.TEST_KEY}1`, member); | ||
| } | ||
|
|
||
| async function writeBackWholeCollectionNeedsDefinedMembers() { | ||
| const collection = await Onyx.get(ONYX_KEYS.COLLECTION.TEST_KEY); | ||
|
|
||
| if (!collection) { | ||
| return; | ||
| } | ||
|
|
||
| // @ts-expect-error undefined members are not valid write input | ||
| await Onyx.setCollection(ONYX_KEYS.COLLECTION.TEST_KEY, collection); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import Onyx from '../../dist/Onyx'; | ||
| import ONYX_KEYS from './setup'; | ||
|
|
||
| async function readsArePositional() { | ||
| const [single, collection] = await Onyx.multiGet([ONYX_KEYS.TEST_KEY, ONYX_KEYS.COLLECTION.TEST_KEY]); | ||
|
|
||
| if (!collection) { | ||
| return single; | ||
| } | ||
|
|
||
| collection.test_1 = {str: 'mutated'}; | ||
|
|
||
| return single; | ||
| } | ||
|
|
||
| async function mixedKeysKeepTheirOwnTypes() { | ||
| const [single, member] = await Onyx.multiGet([ONYX_KEYS.TEST_KEY, `${ONYX_KEYS.COLLECTION.TEST_KEY}1`]); | ||
|
|
||
| if (!member) { | ||
| return single; | ||
| } | ||
|
|
||
| member.str = 'mutated'; | ||
| member.list?.push('appended'); | ||
|
|
||
| return [single, member] as const; | ||
| } | ||
|
|
||
| async function singleKeyListResolvesToTuple() { | ||
| const [single] = await Onyx.multiGet([ONYX_KEYS.TEST_KEY]); | ||
|
|
||
| return single; | ||
| } | ||
|
|
||
| async function writeBackWhatWasRead() { | ||
| const [single, member] = await Onyx.multiGet([ONYX_KEYS.TEST_KEY, `${ONYX_KEYS.COLLECTION.TEST_KEY}1`]); | ||
|
|
||
| await Onyx.set(ONYX_KEYS.TEST_KEY, single ?? null); | ||
|
|
||
| if (!member) { | ||
| return; | ||
| } | ||
|
|
||
| await Onyx.set(`${ONYX_KEYS.COLLECTION.TEST_KEY}1`, member); | ||
| await Onyx.merge(`${ONYX_KEYS.COLLECTION.TEST_KEY}1`, member); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.