Merge pull request #18689 from Snuffleupagus/StructTreeLayerBuilder-render-caching
Improve the `StructTreeLayerBuilder.render` method
This commit is contained in:
commit
4fb045b9eb
@ -76,7 +76,9 @@ const HEADING_PATTERN = /^H(\d+)$/;
|
|||||||
class StructTreeLayerBuilder {
|
class StructTreeLayerBuilder {
|
||||||
#promise;
|
#promise;
|
||||||
|
|
||||||
#treeDom = undefined;
|
#treeDom = null;
|
||||||
|
|
||||||
|
#treePromise;
|
||||||
|
|
||||||
#elementAttributes = new Map();
|
#elementAttributes = new Map();
|
||||||
|
|
||||||
@ -85,13 +87,23 @@ class StructTreeLayerBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async render() {
|
async render() {
|
||||||
if (this.#treeDom !== undefined) {
|
if (this.#treePromise) {
|
||||||
return this.#treeDom;
|
return this.#treePromise;
|
||||||
|
}
|
||||||
|
const { promise, resolve, reject } = Promise.withResolvers();
|
||||||
|
this.#treePromise = promise;
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.#treeDom = this.#walk(await this.#promise);
|
||||||
|
} catch (ex) {
|
||||||
|
reject(ex);
|
||||||
}
|
}
|
||||||
const treeDom = (this.#treeDom = this.#walk(await this.#promise));
|
|
||||||
this.#promise = null;
|
this.#promise = null;
|
||||||
treeDom?.classList.add("structTree");
|
|
||||||
return treeDom;
|
this.#treeDom?.classList.add("structTree");
|
||||||
|
resolve(this.#treeDom);
|
||||||
|
|
||||||
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAriaAttributes(annotationId) {
|
async getAriaAttributes(annotationId) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user