forked from sashin/sashinexists
run npm install to generate a package lock
This commit is contained in:
26
node_modules/function-once/src/index.ts
generated
vendored
Executable file
26
node_modules/function-once/src/index.ts
generated
vendored
Executable file
@@ -0,0 +1,26 @@
|
||||
|
||||
/* MAIN */
|
||||
|
||||
const once = <T> ( fn: (() => T) ): (() => T) => {
|
||||
|
||||
let called = false;
|
||||
let result: T;
|
||||
|
||||
return (): T => {
|
||||
|
||||
if ( !called ) {
|
||||
|
||||
called = true;
|
||||
result = fn ();
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
/* EXPORT */
|
||||
|
||||
export default once;
|
||||
Reference in New Issue
Block a user