diff options
Diffstat (limited to 'excalidraw-app/data/Locker.ts')
| -rw-r--r-- | excalidraw-app/data/Locker.ts | 18 |
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; + } +} |
