MOBILE-3814 core: Remove timeout from waitToBeInDOM
parent
9f61d559b1
commit
e5d748f5e5
|
@ -107,6 +107,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn
|
||||||
protected languageChangedSubscription?: Subscription;
|
protected languageChangedSubscription?: Subscription;
|
||||||
protected resizeListener?: CoreEventObserver;
|
protected resizeListener?: CoreEventObserver;
|
||||||
protected domPromise?: CoreCancellablePromise<void>;
|
protected domPromise?: CoreCancellablePromise<void>;
|
||||||
|
protected buttonsDomPromise?: CoreCancellablePromise<void>;
|
||||||
|
|
||||||
rteEnabled = false;
|
rteEnabled = false;
|
||||||
isPhone = false;
|
isPhone = false;
|
||||||
|
@ -836,7 +837,10 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn
|
||||||
|
|
||||||
const length = await this.toolbarSlides.length();
|
const length = await this.toolbarSlides.length();
|
||||||
|
|
||||||
await CoreDomUtils.waitToBeInDOM(this.toolbar.nativeElement, 5000);
|
// Cancel previous one, if any.
|
||||||
|
this.buttonsDomPromise?.cancel();
|
||||||
|
this.buttonsDomPromise = CoreDomUtils.waitToBeInDOM(this.toolbar.nativeElement);
|
||||||
|
await this.buttonsDomPromise;
|
||||||
|
|
||||||
const width = this.toolbar.nativeElement.getBoundingClientRect().width;
|
const width = this.toolbar.nativeElement.getBoundingClientRect().width;
|
||||||
|
|
||||||
|
@ -1097,6 +1101,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterContentIn
|
||||||
this.labelObserver?.disconnect();
|
this.labelObserver?.disconnect();
|
||||||
this.resizeListener?.off();
|
this.resizeListener?.off();
|
||||||
this.domPromise?.cancel();
|
this.domPromise?.cancel();
|
||||||
|
this.buttonsDomPromise?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,10 +97,9 @@ export class CoreDomUtilsProvider {
|
||||||
* Wait an element to be in dom of another element.
|
* Wait an element to be in dom of another element.
|
||||||
*
|
*
|
||||||
* @param element Element to wait.
|
* @param element Element to wait.
|
||||||
* @param timeout If defined, timeout to wait before rejecting the promise.
|
|
||||||
* @return Cancellable promise.
|
* @return Cancellable promise.
|
||||||
*/
|
*/
|
||||||
waitToBeInDOM(element: HTMLElement, timeout?: number): CoreCancellablePromise<void> {
|
waitToBeInDOM(element: HTMLElement): CoreCancellablePromise<void> {
|
||||||
const root = element.getRootNode({ composed: true });
|
const root = element.getRootNode({ composed: true });
|
||||||
|
|
||||||
if (root === document) {
|
if (root === document) {
|
||||||
|
@ -109,33 +108,24 @@ export class CoreDomUtilsProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
let observer: MutationObserver;
|
let observer: MutationObserver;
|
||||||
let observerTimeout: number | undefined;
|
|
||||||
|
|
||||||
return new CoreCancellablePromise<void>(
|
return new CoreCancellablePromise<void>(
|
||||||
(resolve, reject) => {
|
(resolve) => {
|
||||||
observer = new MutationObserver(() => {
|
observer = new MutationObserver(() => {
|
||||||
const root = element.getRootNode({ composed: true });
|
const root = element.getRootNode({ composed: true });
|
||||||
|
|
||||||
if (root === document) {
|
if (root !== document) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
observer?.disconnect();
|
observer?.disconnect();
|
||||||
observerTimeout && clearTimeout(observerTimeout);
|
|
||||||
resolve();
|
resolve();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (timeout) {
|
|
||||||
observerTimeout = window.setTimeout(() => {
|
|
||||||
observer?.disconnect();
|
|
||||||
|
|
||||||
reject(new Error('Waiting for DOM timeout reached'));
|
|
||||||
}, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
observer.observe(document.body, { subtree: true, childList: true });
|
observer.observe(document.body, { subtree: true, childList: true });
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
observer?.disconnect();
|
observer?.disconnect();
|
||||||
observerTimeout && clearTimeout(observerTimeout);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue