Skip to content

Commit

Permalink
Bugfix of typescript sample: Need to declare a module-local var Promi…
Browse files Browse the repository at this point in the history
…se = 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).
  • Loading branch information
dfahlander committed Mar 12, 2016
1 parent a25da2e commit 4038135
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions samples/typescript/src/app.ts
Expand Up @@ -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 () {

Expand Down
10 changes: 6 additions & 4 deletions 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 {

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 4038135

Please sign in to comment.