fix: only resolve once per selector query
This commit is contained in:
parent
4564aec67f
commit
950c598c5a
|
@ -37,7 +37,7 @@ export class Stage extends decorate(Container) {
|
|||
this._transformRatio = 1;
|
||||
// UI DOM node.
|
||||
this.ui = this.createUiLayer();
|
||||
this._queuedFindSelectors = [];
|
||||
this._queuedFindSelectors = {};
|
||||
// Event handlers.
|
||||
this.onWindowResize = this.onWindowResize.bind(this);
|
||||
window.addEventListener('resize', this.onWindowResize);
|
||||
|
@ -115,18 +115,24 @@ export class Stage extends decorate(Container) {
|
|||
if (node) {
|
||||
return Promise.resolve(node);
|
||||
}
|
||||
const queued = this._queuedFindSelectors[selector];
|
||||
if (queued) {
|
||||
return queued.promise;
|
||||
}
|
||||
let resolve;
|
||||
const promise = new Promise((resolve_) => resolve = resolve_);
|
||||
this._queuedFindSelectors.push({resolve, selector});
|
||||
this._queuedFindSelectors[selector] = {resolve, promise};
|
||||
return promise
|
||||
}
|
||||
|
||||
flushUiElements() {
|
||||
for (let i = 0; i < this._queuedFindSelectors.length; i++) {
|
||||
const {resolve, selector} = this._queuedFindSelectors[i];
|
||||
const selectors = Object.keys(this._queuedFindSelectors);
|
||||
for (let i = 0; i < selectors.length; i++) {
|
||||
const selector = selectors[i];
|
||||
const {resolve} = this._queuedFindSelectors[selector];
|
||||
resolve(this.ui.querySelector(selector));
|
||||
}
|
||||
this._queuedFindSelectors = [];
|
||||
this._queuedFindSelectors = {};
|
||||
}
|
||||
|
||||
focus() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user