From 207e84cff046b7e91391748bff1673aece57cf15 Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Fri, 1 Dec 2023 15:38:48 +0000 Subject: [PATCH] Remove need for cursorRequestMap --- src/wrap-idb-value.ts | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/wrap-idb-value.ts b/src/wrap-idb-value.ts index fa61cc4..2686867 100644 --- a/src/wrap-idb-value.ts +++ b/src/wrap-idb-value.ts @@ -37,10 +37,10 @@ function getCursorAdvanceMethods(): Func[] { ); } -const cursorRequestMap: WeakMap> = - new WeakMap(); -const transactionDoneMap: WeakMap> = - new WeakMap(); +const transactionDoneMap: WeakMap< + IDBTransaction, + Promise +> = new WeakMap(); const transformCache = new WeakMap(); export const reverseTransformCache = new WeakMap(); @@ -62,20 +62,6 @@ function promisifyRequest(request: IDBRequest): Promise { request.addEventListener('error', error); }); - promise - .then((value) => { - // Since cursoring reuses the IDBRequest (*sigh*), we cache it for later retrieval - // (see wrapFunction). - if (value instanceof IDBCursor) { - cursorRequestMap.set( - value as unknown as IDBPCursor, - request as unknown as IDBRequest, - ); - } - // Catching to avoid "Uncaught Promise exceptions" - }) - .catch(() => {}); - // This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This // is because we create many promises from a single IDBRequest. reverseTransformCache.set(promise, request); @@ -159,7 +145,7 @@ function wrapFunction(func: T): Function { // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use // the original object. func.apply(unwrap(this), args); - return wrap(cursorRequestMap.get(this)!); + return wrap(this.request); }; }