From 3e64ebba92a5b3815b7499e4645aae19564d62bf Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Thu, 7 Sep 2023 12:56:02 +0200 Subject: [PATCH 1/2] [TS migration] Migrate 'QueuedOnyxUpdates.js' lib to TypeScript --- ...ueuedOnyxUpdates.js => QueuedOnyxUpdates.ts} | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) rename src/libs/actions/{QueuedOnyxUpdates.js => QueuedOnyxUpdates.ts} (61%) diff --git a/src/libs/actions/QueuedOnyxUpdates.js b/src/libs/actions/QueuedOnyxUpdates.ts similarity index 61% rename from src/libs/actions/QueuedOnyxUpdates.js rename to src/libs/actions/QueuedOnyxUpdates.ts index 486108dd56cf..c8641bbf3029 100644 --- a/src/libs/actions/QueuedOnyxUpdates.js +++ b/src/libs/actions/QueuedOnyxUpdates.ts @@ -1,30 +1,27 @@ import Onyx from 'react-native-onyx'; import ONYXKEYS from '../../ONYXKEYS'; +import {QueuedOnyxUpdates} from '../../types/onyx'; // 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: QueuedOnyxUpdates = []; 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: QueuedOnyxUpdates): Promise { return Onyx.set(ONYXKEYS.QUEUED_ONYX_UPDATES, [...queuedOnyxUpdates, ...updates]); } -function clear() { +function clear(): void { Onyx.set(ONYXKEYS.QUEUED_ONYX_UPDATES, null); } -/** - * @returns {Array} - */ -function getQueuedUpdates() { +function getQueuedUpdates(): QueuedOnyxUpdates { return queuedOnyxUpdates; } From 29f662fba4d4547aa4e1faa822787a5079022024 Mon Sep 17 00:00:00 2001 From: Bartosz Grajdek Date: Tue, 12 Sep 2023 11:24:55 +0200 Subject: [PATCH 2/2] Remove void return & QueuedOnyxUpdates type --- src/libs/actions/QueuedOnyxUpdates.ts | 2 +- src/types/onyx/QueuedOnyxUpdates.ts | 5 ----- src/types/onyx/index.ts | 2 -- 3 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 src/types/onyx/QueuedOnyxUpdates.ts diff --git a/src/libs/actions/QueuedOnyxUpdates.ts b/src/libs/actions/QueuedOnyxUpdates.ts index 1167f9b04417..ac94e6f335e3 100644 --- a/src/libs/actions/QueuedOnyxUpdates.ts +++ b/src/libs/actions/QueuedOnyxUpdates.ts @@ -16,7 +16,7 @@ function queueOnyxUpdates(updates: OnyxUpdate[]): Promise { return Onyx.set(ONYXKEYS.QUEUED_ONYX_UPDATES, [...queuedOnyxUpdates, ...updates]); } -function clear(): void { +function clear() { Onyx.set(ONYXKEYS.QUEUED_ONYX_UPDATES, null); } 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 d908c0b36ce1..98359a269463 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'; @@ -50,7 +49,6 @@ export type { Account, Request, Credentials, - QueuedOnyxUpdates, IOU, Modal, Network,