diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 314685fae94f..af060ea58901 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -1,4 +1,5 @@ import {ValueOf} from 'type-fest'; +import {OnyxUpdate} from 'react-native-onyx'; import DeepValueOf from './types/utils/DeepValueOf'; import * as OnyxTypes from './types/onyx'; import CONST from './CONST'; @@ -301,7 +302,7 @@ type OnyxValues = { [ONYXKEYS.DEVICE_ID]: string; [ONYXKEYS.IS_SIDEBAR_LOADED]: boolean; [ONYXKEYS.PERSISTED_REQUESTS]: OnyxTypes.Request[]; - [ONYXKEYS.QUEUED_ONYX_UPDATES]: OnyxTypes.QueuedOnyxUpdates; + [ONYXKEYS.QUEUED_ONYX_UPDATES]: OnyxUpdate[]; [ONYXKEYS.CURRENT_DATE]: string; [ONYXKEYS.CREDENTIALS]: OnyxTypes.Credentials; [ONYXKEYS.IOU]: OnyxTypes.IOU; diff --git a/src/libs/actions/QueuedOnyxUpdates.js b/src/libs/actions/QueuedOnyxUpdates.ts similarity index 64% rename from src/libs/actions/QueuedOnyxUpdates.js rename to src/libs/actions/QueuedOnyxUpdates.ts index 06f15be1340f..ac94e6f335e3 100644 --- a/src/libs/actions/QueuedOnyxUpdates.js +++ b/src/libs/actions/QueuedOnyxUpdates.ts @@ -1,19 +1,18 @@ -import Onyx from 'react-native-onyx'; +import Onyx, {OnyxUpdate} from 'react-native-onyx'; import ONYXKEYS from '../../ONYXKEYS'; // In this file we manage a queue of Onyx updates while the SequentialQueue is processing. There are functions to get the updates and clear the queue after saving the updates in Onyx. -let queuedOnyxUpdates = []; +let queuedOnyxUpdates: OnyxUpdate[] = []; Onyx.connect({ key: ONYXKEYS.QUEUED_ONYX_UPDATES, - callback: (val) => (queuedOnyxUpdates = val || []), + callback: (val) => (queuedOnyxUpdates = val ?? []), }); /** - * @param {Array} updates Onyx updates to queue for later - * @returns {Promise} + * @param updates Onyx updates to queue for later */ -function queueOnyxUpdates(updates) { +function queueOnyxUpdates(updates: OnyxUpdate[]): Promise { return Onyx.set(ONYXKEYS.QUEUED_ONYX_UPDATES, [...queuedOnyxUpdates, ...updates]); } @@ -21,10 +20,7 @@ function clear() { Onyx.set(ONYXKEYS.QUEUED_ONYX_UPDATES, null); } -/** - * @returns {Promise} - */ -function flushQueue() { +function flushQueue(): Promise { return Onyx.update(queuedOnyxUpdates).then(clear); } diff --git a/src/types/onyx/QueuedOnyxUpdates.ts b/src/types/onyx/QueuedOnyxUpdates.ts deleted file mode 100644 index 40daa2e09335..000000000000 --- a/src/types/onyx/QueuedOnyxUpdates.ts +++ /dev/null @@ -1,5 +0,0 @@ -import Onyx from 'react-native-onyx'; - -type QueuedOnyxUpdates = Array; - -export default QueuedOnyxUpdates; diff --git a/src/types/onyx/index.ts b/src/types/onyx/index.ts index a0cf0e5f743b..8711a0d208ef 100644 --- a/src/types/onyx/index.ts +++ b/src/types/onyx/index.ts @@ -1,7 +1,6 @@ import Account from './Account'; import Request from './Request'; import Credentials from './Credentials'; -import QueuedOnyxUpdates from './QueuedOnyxUpdates'; import IOU from './IOU'; import Modal from './Modal'; import Network from './Network'; @@ -52,7 +51,6 @@ export type { Account, Request, Credentials, - QueuedOnyxUpdates, IOU, Modal, Network,