X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FUtils.ts;h=58e9094c7a601bcd587cf59e6fd79b32a8823b95;hb=5f742aac345f2eb8897c24651d00c7fb43dabbf8;hp=9b8074214a3440fee1201c40c297af2e15c6f784;hpb=473045b1407bdddde5728f3ef3c1e6b078e18e30;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 9b807421..58e9094c 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -382,3 +382,18 @@ export const isArraySorted = (array: T[], compareFn: (a: T, b: T) => number): } return true; }; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const once = ( + fn: (...args: A) => R, + context: T, +): ((...args: A) => R) => { + let result: R; + return (...args: A) => { + if (fn) { + result = fn.apply(context, args); + (fn as unknown as undefined) = (context as unknown as undefined) = undefined; + } + return result; + }; +};