X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=ui%2Fweb%2Fsrc%2Fcomposables%2FUtils.ts;h=7f070e49a8aa7fde7f8e268f6369172494c8e13c;hb=6f9618c30217a9ddee12830fe5f77e6cabe7296e;hp=8ce3b6eca5b37c27dca29faf6a970ea8a0f9a980;hpb=afb26ef122e3517f1b6a32c14d7ffe92c0ae35a0;p=e-mobility-charging-stations-simulator.git diff --git a/ui/web/src/composables/Utils.ts b/ui/web/src/composables/Utils.ts index 8ce3b6ec..7f070e49 100644 --- a/ui/web/src/composables/Utils.ts +++ b/ui/web/src/composables/Utils.ts @@ -1,47 +1,19 @@ -export default class Utils { - // STATE - public static isUndefined(value: unknown): boolean { - return typeof value === 'undefined'; - } - - public static ifUndefined(value: T | undefined, isValue: T): T { - if (Utils.isUndefined(value) === true) return isValue; - return value as T; - } - - public static isIterable(obj: T): boolean { - if (obj === null || obj === undefined) { - return false; - } - return typeof (obj as any)[Symbol.iterator] === 'function'; - } - - // public static ifNotIterableDo(obj: T, cb: () => void): void { - // if (this.isIterable(obj) === false) cb(); - // } +export const ifUndefined = (value: T | undefined, isValue: T): T => { + if (value === undefined) return isValue + return value as T +} - public static async promiseWithTimeout( - promise: Promise, - timeoutMs: number, - timeoutError: Error, - timeoutCallback: () => void = () => { - /* This is intentional */ - } - ): Promise { - // Create a timeout promise that rejects in timeout milliseconds - const timeoutPromise = new Promise((_, reject) => { - setTimeout(() => { - timeoutCallback(); - reject(timeoutError); - }, timeoutMs); - }); +// const isIterable = (obj: T): boolean => { +// if (obj == null) { +// return false +// } +// return typeof (obj as unknown as Iterable)[Symbol.iterator] === 'function' +// } - // Returns a race between timeout promise and the passed promise - return Promise.race([promise, timeoutPromise]); - } +// const ifNotIterableDo = (obj: T, cb: () => void): void => { +// if (isIterable(obj) === false) cb() +// } - // FUNCTIONAL - // public static compose(...fns: ((arg: T) => T)[]): (x: T) => T { - // return (x: T) => fns.reduceRight((y, fn) => fn(y), x); - // } -} +// export const compose = (...fns: ((arg: T) => T)[]): ((x: T) => T) => { +// return (x: T) => fns.reduceRight((y, fn) => fn(y), x) +// }