mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-18 11:45:38 +02:00
fix: Clean up and add Neon DB
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
export * from "./id"
|
||||
export * from "./fn"
|
||||
export * from "./log"
|
||||
export * from "./invite"
|
||||
export * from "./helper"
|
||||
export * from "./id";
|
||||
export * from "./fn";
|
||||
export * from "./log";
|
||||
export * from "./invite";
|
||||
export * from "./helper";
|
||||
export * from "./memo";
|
||||
|
||||
18
cloud/packages/core/src/utils/memo.ts
Normal file
18
cloud/packages/core/src/utils/memo.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export function memo<T>(fn: () => T, cleanup?: (input: T) => Promise<void>) {
|
||||
let value: T | undefined;
|
||||
let loaded = false;
|
||||
|
||||
const result = (): T => {
|
||||
if (loaded) return value as T;
|
||||
loaded = true;
|
||||
value = fn();
|
||||
return value as T;
|
||||
};
|
||||
result.reset = async () => {
|
||||
if (cleanup && value) await cleanup(value);
|
||||
loaded = false;
|
||||
value = undefined;
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user