aboutsummaryrefslogtreecommitdiff
path: root/src/query.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/query.ts')
-rw-r--r--src/query.ts9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/query.ts b/src/query.ts
index dffff86eb..ee1ac2603 100644
--- a/src/query.ts
+++ b/src/query.ts
@@ -658,13 +658,13 @@ export class QueryRoot {
/**
* Get, modify and store an element inside a transaction.
*/
- mutate<T>(store: Store<T>, key: any, f: (v: T) => T): QueryRoot {
+ mutate<T>(store: Store<T>, key: any, f: (v: T|undefined) => T|undefined): QueryRoot {
this.checkFinished();
const doPut = (tx: IDBTransaction) => {
const reqGet = tx.objectStore(store.name).get(key);
reqGet.onsuccess = () => {
const r = reqGet.result;
- let m: T;
+ let m: T|undefined;
try {
m = f(r);
} catch (e) {
@@ -674,8 +674,9 @@ export class QueryRoot {
}
throw e;
}
-
- tx.objectStore(store.name).put(m);
+ if (m !== undefined && m !== null) {
+ tx.objectStore(store.name).put(m);
+ }
};
};
this.scheduleFinish();