Skip to content

Commit

Permalink
Merge pull request #26944 from software-mansion-labs/ts-migration/que…
Browse files Browse the repository at this point in the history
…ued-onyx-updates
  • Loading branch information
cead22 authored Sep 19, 2023
2 parents 8af37c3 + 29f662f commit b49b0be
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
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<Object>} 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<void> {
return Onyx.set(ONYXKEYS.QUEUED_ONYX_UPDATES, [...queuedOnyxUpdates, ...updates]);
}

function clear() {
Onyx.set(ONYXKEYS.QUEUED_ONYX_UPDATES, null);
}

/**
* @returns {Promise}
*/
function flushQueue() {
function flushQueue(): Promise<void> {
return Onyx.update(queuedOnyxUpdates).then(clear);
}

Expand Down
5 changes: 0 additions & 5 deletions src/types/onyx/QueuedOnyxUpdates.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/types/onyx/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -52,7 +51,6 @@ export type {
Account,
Request,
Credentials,
QueuedOnyxUpdates,
IOU,
Modal,
Network,
Expand Down

0 comments on commit b49b0be

Please sign in to comment.