Fix StartOS 0.4 TypeScript packaging to match SDK API
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.once = once;
|
||||
/**
|
||||
* Wraps a function so it is only executed once. Subsequent calls return the cached result.
|
||||
*
|
||||
* @param fn - The function to execute at most once
|
||||
* @returns A wrapper that lazily evaluates `fn` on first call and caches the result
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const getConfig = once(() => loadExpensiveConfig())
|
||||
* getConfig() // loads config
|
||||
* getConfig() // returns cached result
|
||||
* ```
|
||||
*/
|
||||
function once(fn) {
|
||||
let result = [];
|
||||
return () => {
|
||||
if (!result.length) {
|
||||
result = [fn()];
|
||||
}
|
||||
return result[0];
|
||||
};
|
||||
}
|
||||
//# sourceMappingURL=once.js.map
|
||||
Reference in New Issue
Block a user