Skip to content
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

[No QA] [TS migration] Migrate 'QueuedOnyxUpdates.js' lib to TypeScript #26944

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -306,7 +307,7 @@ type OnyxValues = {
[ONYXKEYS.IS_SIDEBAR_LOADED]: boolean;
[ONYXKEYS.SHOW_DOWNLOAD_APP_BANNER]: boolean;
[ONYXKEYS.PERSISTED_REQUESTS]: OnyxTypes.Request[];
[ONYXKEYS.QUEUED_ONYX_UPDATES]: OnyxTypes.QueuedOnyxUpdates;
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved
[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() {
function clear(): void {
Onyx.set(ONYXKEYS.QUEUED_ONYX_UPDATES, null);
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved
}

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

Expand Down
Loading