diff options
author | siikamiika <siikamiika@users.noreply.github.com> | 2020-02-14 11:00:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-14 11:00:36 +0200 |
commit | c09a3ded1d694887e4e9ff48cc3c387abdbb2065 (patch) | |
tree | af4a70e78ecc76a9e93ffcd23323f48c9da89d35 /ext/mixed/js/display.js | |
parent | e645296b1b5e993355844f2cb2b026b87d05759e (diff) | |
parent | 810a7e7d92d15412974810702d954de60453dd31 (diff) |
Merge pull request #357 from siikamiika/simplify-display-prepare
Simplify display prepare
Diffstat (limited to 'ext/mixed/js/display.js')
-rw-r--r-- | ext/mixed/js/display.js | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index b18e275d..178567ab 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -48,6 +48,13 @@ class Display { this.setInteractive(true); } + async prepare(options=null) { + const displayGeneratorPromise = this.displayGenerator.prepare(); + const updateOptionsPromise = this.updateOptions(options); + await Promise.all([displayGeneratorPromise, updateOptionsPromise]); + yomichan.on('optionsUpdate', () => this.updateOptions(null)); + } + onError(_error) { throw new Error('Override me'); } @@ -243,15 +250,6 @@ class Display { throw new Error('Override me'); } - isInitialized() { - return this.options !== null; - } - - async initialize(options=null) { - await this.updateOptions(options); - yomichan.on('optionsUpdate', () => this.updateOptions(null)); - } - async updateOptions(options) { this.options = options ? options : await apiOptionsGet(this.getOptionsContext()); this.updateDocumentOptions(this.options); @@ -362,7 +360,6 @@ class Display { async setContentTerms(definitions, context, token) { if (!context) { throw new Error('Context expected'); } - if (!this.isInitialized()) { return; } this.setEventListenersActive(false); @@ -370,10 +367,7 @@ class Display { window.focus(); } - if (!this.displayGenerator.isInitialized()) { - await this.displayGenerator.initialize(); - if (this.setContentToken !== token) { return; } - } + if (this.setContentToken !== token) { return; } this.definitions = definitions; if (context.disableHistory) { @@ -426,7 +420,6 @@ class Display { async setContentKanji(definitions, context, token) { if (!context) { throw new Error('Context expected'); } - if (!this.isInitialized()) { return; } this.setEventListenersActive(false); @@ -434,10 +427,7 @@ class Display { window.focus(); } - if (!this.displayGenerator.isInitialized()) { - await this.displayGenerator.initialize(); - if (this.setContentToken !== token) { return; } - } + if (this.setContentToken !== token) { return; } this.definitions = definitions; if (context.disableHistory) { |