From 4038135330912322a0f194ab7e4d75acac61353f Mon Sep 17 00:00:00 2001 From: David Fahlander Date: Sun, 13 Mar 2016 00:51:52 +0100 Subject: [PATCH] Bugfix of typescript sample: Need to declare a module-local var Promise = Dexie.Promise in all modules that will use async/await if they should do async/await with Dexie.Promise (which is required when within a transaction). --- samples/typescript/src/app.ts | 5 +++-- samples/typescript/src/appdb.ts | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/samples/typescript/src/app.ts b/samples/typescript/src/app.ts index cbc2a134f..32463e7a3 100644 --- a/samples/typescript/src/app.ts +++ b/samples/typescript/src/app.ts @@ -3,8 +3,9 @@ import Dexie from 'dexie'; import Console from './console'; import {db,Contact} from './appdb'; -const all = Dexie.Promise.all; -const console = new Console(); // So that you dont have to press F12... +const Promise = Dexie.Promise, // KEEP! (or loose transaction safety in await calls!) + all = Promise.all, + console = new Console(); // So that you dont have to press F12... document.addEventListener('DOMContentLoaded', async function () { diff --git a/samples/typescript/src/appdb.ts b/samples/typescript/src/appdb.ts index 819a3ca0b..aeef8330a 100644 --- a/samples/typescript/src/appdb.ts +++ b/samples/typescript/src/appdb.ts @@ -1,5 +1,7 @@ import Dexie from 'dexie'; -const all = Dexie.Promise.all; + +const Promise = Dexie.Promise; // KEEP! (or loose transaction safety in await calls!) +const all = Promise.all; export class AppDatabase extends Dexie { @@ -82,17 +84,17 @@ export class Contact { save() { return db.transaction('rw', db.contacts, db.emails, db.phones, async () => { - + let [emailIds, phoneIds] = await all ( // Save existing arrays all(this.emails.map(email => db.emails.put(email))), all(this.phones.map(phone => db.phones.put(phone)))); - + // Remove items from DB that is was not saved here: await db.emails.where('contactId').equals(this.id) .and(email => emailIds.indexOf(email.id) === -1) .delete(); - + await db.phones.where('contactId').equals(this.id) .and(phone => phoneIds.indexOf(phone.id) === -1) .delete();