Skip to content

Commit

Permalink
Remove need for cursorRequestMap
Browse files Browse the repository at this point in the history
  • Loading branch information
jakearchibald committed Dec 1, 2023
1 parent bdcb5b5 commit 207e84c
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/wrap-idb-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ function getCursorAdvanceMethods(): Func[] {
);
}

const cursorRequestMap: WeakMap<IDBPCursor, IDBRequest<IDBCursor>> =
new WeakMap();
const transactionDoneMap: WeakMap<IDBTransaction, Promise<void>> =
new WeakMap();
const transactionDoneMap: WeakMap<
IDBTransaction,
Promise<void>
> = new WeakMap();
const transformCache = new WeakMap();
export const reverseTransformCache = new WeakMap();

Expand All @@ -62,20 +62,6 @@ function promisifyRequest<T>(request: IDBRequest<T>): Promise<T> {
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<IDBCursor>,
);
}
// 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);
Expand Down Expand Up @@ -159,7 +145,7 @@ function wrapFunction<T extends Func>(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);
};
}

Expand Down

0 comments on commit 207e84c

Please sign in to comment.