summaryrefslogtreecommitdiffhomepage
path: root/cloud/core/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'cloud/core/src/util')
-rw-r--r--cloud/core/src/util/memo.ts11
1 files changed, 11 insertions, 0 deletions
diff --git a/cloud/core/src/util/memo.ts b/cloud/core/src/util/memo.ts
new file mode 100644
index 000000000..3c84cf1fb
--- /dev/null
+++ b/cloud/core/src/util/memo.ts
@@ -0,0 +1,11 @@
+export function memo<T>(fn: () => T) {
+ let value: T | undefined
+ let loaded = false
+
+ return (): T => {
+ if (loaded) return value as T
+ loaded = true
+ value = fn()
+ return value as T
+ }
+}