This repository has been archived on 2025-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
project-client/src/shared/utils/once.ts
2023-04-04 00:41:52 +02:00

8 lines
231 B
TypeScript

export function once<T extends Function>(fn: T): T {
let called = false;
return function (this: any, ...args: any[]) {
if (called) return;
called = true;
return fn.apply(this, args);
} as any;
}