simplify DisplayGenerator initialization
This commit is contained in:
parent
65dfb855fb
commit
93eaee9765
@ -19,9 +19,6 @@
|
|||||||
|
|
||||||
class DisplayGenerator {
|
class DisplayGenerator {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._isInitialized = false;
|
|
||||||
this._initializationPromise = null;
|
|
||||||
|
|
||||||
this._termEntryTemplate = null;
|
this._termEntryTemplate = null;
|
||||||
this._termExpressionTemplate = null;
|
this._termExpressionTemplate = null;
|
||||||
this._termDefinitionItemTemplate = null;
|
this._termDefinitionItemTemplate = null;
|
||||||
@ -40,18 +37,10 @@ class DisplayGenerator {
|
|||||||
this._tagFrequencyTemplate = null;
|
this._tagFrequencyTemplate = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
isInitialized() {
|
async prepare() {
|
||||||
return this._isInitialized;
|
const html = await apiGetDisplayTemplatesHtml();
|
||||||
}
|
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||||
|
this._setTemplates(doc);
|
||||||
initialize() {
|
|
||||||
if (this._isInitialized) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
if (this._initializationPromise === null) {
|
|
||||||
this._initializationPromise = this._initializeInternal();
|
|
||||||
}
|
|
||||||
return this._initializationPromise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createTermEntry(details) {
|
createTermEntry(details) {
|
||||||
@ -303,13 +292,6 @@ class DisplayGenerator {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _initializeInternal() {
|
|
||||||
const html = await apiGetDisplayTemplatesHtml();
|
|
||||||
const doc = new DOMParser().parseFromString(html, 'text/html');
|
|
||||||
this._setTemplates(doc);
|
|
||||||
this._isInitialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_setTemplates(doc) {
|
_setTemplates(doc) {
|
||||||
this._termEntryTemplate = doc.querySelector('#term-entry-template');
|
this._termEntryTemplate = doc.querySelector('#term-entry-template');
|
||||||
this._termExpressionTemplate = doc.querySelector('#term-expression-template');
|
this._termExpressionTemplate = doc.querySelector('#term-expression-template');
|
||||||
|
@ -243,6 +243,7 @@ class Display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async initialize(options=null) {
|
async initialize(options=null) {
|
||||||
|
await this.displayGenerator.prepare();
|
||||||
await this.updateOptions(options);
|
await this.updateOptions(options);
|
||||||
yomichan.on('optionsUpdate', () => this.updateOptions(null));
|
yomichan.on('optionsUpdate', () => this.updateOptions(null));
|
||||||
}
|
}
|
||||||
@ -365,10 +366,7 @@ class Display {
|
|||||||
window.focus();
|
window.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.displayGenerator.isInitialized()) {
|
if (this.setContentToken !== token) { return; }
|
||||||
await this.displayGenerator.initialize();
|
|
||||||
if (this.setContentToken !== token) { return; }
|
|
||||||
}
|
|
||||||
|
|
||||||
this.definitions = definitions;
|
this.definitions = definitions;
|
||||||
if (context.disableHistory) {
|
if (context.disableHistory) {
|
||||||
@ -429,10 +427,7 @@ class Display {
|
|||||||
window.focus();
|
window.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.displayGenerator.isInitialized()) {
|
if (this.setContentToken !== token) { return; }
|
||||||
await this.displayGenerator.initialize();
|
|
||||||
if (this.setContentToken !== token) { return; }
|
|
||||||
}
|
|
||||||
|
|
||||||
this.definitions = definitions;
|
this.definitions = definitions;
|
||||||
if (context.disableHistory) {
|
if (context.disableHistory) {
|
||||||
|
Loading…
Reference in New Issue
Block a user