From 90d7b73dd4b6e328667f7e89132f9352d2d5b547 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 17 Nov 2021 11:08:29 +0100 Subject: [PATCH] non-persisted queued items don't have an id yet, find them by ref equality --- src/logging/IDBLogger.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/logging/IDBLogger.ts b/src/logging/IDBLogger.ts index 944116b8..ebcf2249 100644 --- a/src/logging/IDBLogger.ts +++ b/src/logging/IDBLogger.ts @@ -152,12 +152,14 @@ export class IDBLogger extends BaseLogger { const txn = db.transaction(["logs"], "readwrite"); const logs = txn.objectStore("logs"); for (const item of items) { - const queuedIdx = this._queuedItems.findIndex(i => i.id === item.id); - if (queuedIdx === -1) { - // todo: isn't id optional? do we need further checks here - logs.delete(item.id!); // resolve questionable use of non-null assertion operator? + if (typeof item.id === "number") { + logs.delete(item.id); } else { - this._queuedItems.splice(queuedIdx, 1); + // assume the (non-persisted) object in each array will be the same + const queuedIdx = this._queuedItems.indexOf(item); + if (queuedIdx === -1) { + this._queuedItems.splice(queuedIdx, 1); + } } } await txnAsPromise(txn);