From c55ba3b2be267d9dc616bda1a293d136c63cd639 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 29 Aug 2016 19:51:37 -0700 Subject: WIP --- ext/bg/js/dictionary.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index b7b7039c..7cfa58a8 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -19,8 +19,8 @@ class Dictionary { constructor() { - this.db = null; this.entities = null; + this.db = new Dexie('dict'); } existsDb() { @@ -29,8 +29,6 @@ class Dictionary { initDb() { this.entities = null; - - this.db = new Dexie('dict'); this.db.version(1).stores({ terms: '++id,expression,reading', entities: '++,name', @@ -46,11 +44,16 @@ class Dictionary { reading: row.reading, tags: row.tags.split(' '), glossary: row.glossary, - entities: this.entities, id: row.id }); }).then(() => { - return Promise.resolve(results); + return this.getEntities(); + }).then((entities) => { + for (const result of results) { + result.entities = entities; + } + + return results; }); } @@ -67,9 +70,9 @@ class Dictionary { }); } - getEntities() { + getEntities(tags) { if (this.entities !== null) { - return Promise.resolve(this.entities); + return this.entities; } return this.db.entities.toArray((rows) => { @@ -77,8 +80,8 @@ class Dictionary { for (const row of rows) { this.entities[row.name] = row.value; } - }).then(() => { - return Promise.resolve(this.entities); + + return this.entities; }); } -- cgit v1.2.3