summaryrefslogtreecommitdiffstats
path: root/excalidraw-app/data/Locker.ts
diff options
context:
space:
mode:
authorkj_sh6042026-03-15 16:19:35 -0400
committerkj_sh6042026-03-15 16:19:35 -0400
commitbfc2cec7d43eb8eaa46dd3f91084932381257059 (patch)
tree0857e3aac2cff922826d4871ff54536b26fad6fc /excalidraw-app/data/Locker.ts
parent225db4a7805befe009fe055fc2ef5daedd6c04f9 (diff)
refactor: excalidraw-app/
Diffstat (limited to 'excalidraw-app/data/Locker.ts')
-rw-r--r--excalidraw-app/data/Locker.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/excalidraw-app/data/Locker.ts b/excalidraw-app/data/Locker.ts
new file mode 100644
index 0000000..c99673e
--- /dev/null
+++ b/excalidraw-app/data/Locker.ts
@@ -0,0 +1,18 @@
+export class Locker<T extends string> {
+ private locks = new Map<T, true>();
+
+ lock = (lockType: T) => {
+ this.locks.set(lockType, true);
+ };
+
+ /** @returns whether no locks remaining */
+ unlock = (lockType: T) => {
+ this.locks.delete(lockType);
+ return !this.isLocked();
+ };
+
+ /** @returns whether some (or specific) locks are present */
+ isLocked(lockType?: T) {
+ return lockType ? this.locks.has(lockType) : !!this.locks.size;
+ }
+}