From 528dd50dcd32942e6d632bbece68ef9668c3fde0 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Mon, 25 Sep 2023 11:45:09 -0300 Subject: [PATCH] Make Locks.prototype.getLocksForConnectionId private MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whilst working on MMB-156 I asked whether this was meant to be part of the public API and was told no, and that its usage should be replaced by Locks.prototype.getSelf. I have no idea whether the `delay(60)` preceding the call to releaseMyLocks in the useElementSelect hook is still necessary, since I don’t know what the "spaces API" that it refers to is. --- demo/src/hooks/useElementSelect.ts | 2 +- demo/src/utils/locking.ts | 7 ++----- src/Locks.ts | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/demo/src/hooks/useElementSelect.ts b/demo/src/hooks/useElementSelect.ts index be873b66..d29adbf3 100644 --- a/demo/src/hooks/useElementSelect.ts +++ b/demo/src/hooks/useElementSelect.ts @@ -42,7 +42,7 @@ export const useClickOutside = (ref: MutableRefObject, self? await space.locations.set({ slide: self.location?.slide, element: undefined }); // TODO delete this workaround when spaces API is ready await delay(60); - await releaseMyLocks(space, self); + await releaseMyLocks(space); } }; diff --git a/demo/src/utils/locking.ts b/demo/src/utils/locking.ts index b1fbe331..5615b9dc 100644 --- a/demo/src/utils/locking.ts +++ b/demo/src/utils/locking.ts @@ -1,10 +1,7 @@ import { Space } from '@ably/spaces'; -import { Member } from './types'; -export const releaseMyLocks = async (space: Space, self: Member) => { - await Promise.all([ - ...space.locks.getLocksForConnectionId(self.connectionId).map((lock) => space.locks.release(lock.id)), - ]); +export const releaseMyLocks = async (space: Space) => { + await Promise.all([...space.locks.getSelf().map((lock) => space.locks.release(lock.id))]); }; export const buildLockId = (slide: string | undefined, element: string | undefined) => diff --git a/src/Locks.ts b/src/Locks.ts index c0b94b6c..8e6eba2f 100644 --- a/src/Locks.ts +++ b/src/Locks.ts @@ -292,7 +292,7 @@ export default class Locks extends EventEmitter { return locks.delete(connectionId); } - getLocksForConnectionId(connectionId: string): Lock[] { + private getLocksForConnectionId(connectionId: string): Lock[] { const requests: Lock[] = []; for (const locks of this.locks.values()) {