-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56046 from callstack-internal/improve-import-onyx…
…-performance
- Loading branch information
Showing
6 changed files
with
126 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,25 @@ | ||
import type {OnyxEntry, OnyxKey} from 'react-native-onyx'; | ||
import Onyx from 'react-native-onyx'; | ||
import type {OnyxCollectionKey, OnyxCollectionValuesMapping, OnyxValues} from '@src/ONYXKEYS'; | ||
import type CollectionDataSet from '@src/types/utils/CollectionDataSet'; | ||
import {KEYS_TO_PRESERVE} from './App'; | ||
|
||
function clearOnyxStateBeforeImport(): Promise<void> { | ||
return Onyx.clear(KEYS_TO_PRESERVE); | ||
} | ||
|
||
function importOnyxCollectionState(collectionsMap: Map<keyof OnyxCollectionValuesMapping, CollectionDataSet<OnyxCollectionKey>>): Promise<void[]> { | ||
const collectionPromises = Array.from(collectionsMap.entries()).map(([baseKey, items]) => { | ||
return items ? Onyx.setCollection(baseKey, items) : Promise.resolve(); | ||
}); | ||
return Promise.all(collectionPromises); | ||
} | ||
|
||
function importOnyxRegularState(state: Partial<Record<OnyxKey, OnyxEntry<OnyxKey>>>): Promise<void> { | ||
if (Object.keys(state).length > 0) { | ||
return Onyx.multiSet(state as Partial<OnyxValues>); | ||
} | ||
return Promise.resolve(); | ||
} | ||
|
||
export {clearOnyxStateBeforeImport, importOnyxCollectionState, importOnyxRegularState}; |
This file contains 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