Skip to content

Commit

Permalink
Merge branch 'Expensify:main' into fix/update-order
Browse files Browse the repository at this point in the history
  • Loading branch information
paultsimura committed Mar 5, 2024
2 parents d0d261b + 69b2d59 commit 0628fe5
Show file tree
Hide file tree
Showing 16 changed files with 274 additions and 218 deletions.
13 changes: 0 additions & 13 deletions lib/Logger.d.ts

This file was deleted.

31 changes: 0 additions & 31 deletions lib/Logger.js

This file was deleted.

31 changes: 31 additions & 0 deletions lib/Logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
type LogData = {
message: string;
level: 'alert' | 'info';
};
type LoggerCallback = (data: LogData) => void;

// eslint-disable-next-line @typescript-eslint/no-empty-function
let logger: LoggerCallback = () => {};

/**
* Register the logging callback
*/
function registerLogger(callback: LoggerCallback) {
logger = callback;
}

/**
* Send an alert message to the logger
*/
function logAlert(message: string) {
logger({message: `[Onyx] ${message}`, level: 'alert'});
}

/**
* Send an info message to the logger
*/
function logInfo(message: string) {
logger({message: `[Onyx] ${message}`, level: 'info'});
}

export {registerLogger, logInfo, logAlert};
27 changes: 0 additions & 27 deletions lib/Str.js

This file was deleted.

24 changes: 24 additions & 0 deletions lib/Str.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Returns true if the haystack begins with the needle
*
* @param haystack The full string to be searched
* @param needle The case-sensitive string to search for
* @return Returns true if the haystack starts with the needle.
*/
function startsWith(haystack: string, needle: string) {
return typeof haystack === 'string' && typeof needle === 'string' && haystack.startsWith(needle);
}

/**
* Checks if parameter is a string or function.
* If it is a string, then we will just return it.
* If it is a function, then we will call it with
* any additional arguments and return the result.
*/
function result(parameter: string): string;
function result<TFunction extends (...a: TArgs) => unknown, TArgs extends unknown[]>(parameter: TFunction, ...args: TArgs): ReturnType<TFunction>;
function result<TFunction extends (...a: TArgs) => unknown, TArgs extends unknown[]>(parameter: TFunction, ...args: TArgs): ReturnType<TFunction> | string {
return typeof parameter === 'function' ? (parameter(...args) as ReturnType<TFunction>) : parameter;
}

export {startsWith, result};
59 changes: 0 additions & 59 deletions lib/SyncQueue.js

This file was deleted.

34 changes: 0 additions & 34 deletions lib/compose.js

This file was deleted.

13 changes: 8 additions & 5 deletions lib/createDeferredTask.js → lib/createDeferredTask.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
type DeferredTask = {
promise: Promise<void>;
resolve?: () => void;
};

/**
* Create a deferred task that can be resolved when we call `resolve()`
* The returned promise will complete when we call `resolve`
* Useful when we want to wait for a tasks that is resolved from an external action
*
* @template T
* @returns {{ resolve: function(*), promise: Promise<T|void> }}
*/
export default function createDeferredTask() {
const deferred = {};
export default function createDeferredTask(): DeferredTask {
const deferred = {} as DeferredTask;

deferred.promise = new Promise((res) => {
deferred.resolve = res;
});
Expand Down
1 change: 1 addition & 0 deletions lib/storage/__mocks__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const set = jest.fn((key, value) => {
});

const idbKeyvalMock: StorageProvider = {
name: 'KeyValMockProvider',
init: () => undefined,
setItem(key, value) {
return set(key, value);
Expand Down
Loading

0 comments on commit 0628fe5

Please sign in to comment.