X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=ui%2Fweb%2Fsrc%2Fcomposables%2FUtils.ts;h=7f070e49a8aa7fde7f8e268f6369172494c8e13c;hb=6f9618c30217a9ddee12830fe5f77e6cabe7296e;hp=851ba4318fc337474875025a85d900799ce2ebbf;hpb=17fdc576ac00c9e3a8e67a11dc2ddee9867636cc;p=e-mobility-charging-stations-simulator.git diff --git a/ui/web/src/composables/Utils.ts b/ui/web/src/composables/Utils.ts index 851ba431..7f070e49 100644 --- a/ui/web/src/composables/Utils.ts +++ b/ui/web/src/composables/Utils.ts @@ -1,50 +1,19 @@ -const isUndefined = (value: unknown): boolean => { - return typeof value === 'undefined'; -}; - export const ifUndefined = (value: T | undefined, isValue: T): T => { - if (isUndefined(value) === true) return isValue; - return value as T; -}; + if (value === undefined) return isValue + return value as T +} // const isIterable = (obj: T): boolean => { -// if (obj === null || obj === undefined) { -// return false; +// if (obj == null) { +// return false // } -// return typeof (obj as unknown as Iterable)[Symbol.iterator] === 'function'; -// }; +// return typeof (obj as unknown as Iterable)[Symbol.iterator] === 'function' +// } // const ifNotIterableDo = (obj: T, cb: () => void): void => { -// if (isIterable(obj) === false) cb(); -// }; - -const isPromisePending = (promise: Promise): boolean => { - return util.inspect(promise).includes('pending'); -}; - -export const 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(() => { - if (isPromisePending(promise)) { - timeoutCallback(); - // FIXME: The original promise shall be canceled - } - reject(timeoutError); - }, timeoutMs); - }); - - // Returns a race between timeout promise and the passed promise - return Promise.race([promise, timeoutPromise]); -}; +// if (isIterable(obj) === false) cb() +// } // export const compose = (...fns: ((arg: T) => T)[]): ((x: T) => T) => { -// return (x: T) => fns.reduceRight((y, fn) => fn(y), x); -// }; +// return (x: T) => fns.reduceRight((y, fn) => fn(y), x) +// }