Merge pull request #3173 from crazyserver/MOBILE-3814
MOBILE-3814 chore: Refactor waitToDom and rename it to waitToBeInDOMmain
commit
cd323719db
|
@ -89,7 +89,7 @@ export class CoreCollapsibleItemDirective implements OnInit {
|
||||||
* @return Promise resolved when loadings are done.
|
* @return Promise resolved when loadings are done.
|
||||||
*/
|
*/
|
||||||
protected async waitLoadingsDone(): Promise<void> {
|
protected async waitLoadingsDone(): Promise<void> {
|
||||||
await CoreDomUtils.waitToDom(this.element);
|
await CoreDomUtils.waitToBeInDOM(this.element);
|
||||||
|
|
||||||
const page = this.element.closest('.ion-page');
|
const page = this.element.closest('.ion-page');
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ import { NavigationStart } from '@angular/router';
|
||||||
import { filter } from 'rxjs/operators';
|
import { filter } from 'rxjs/operators';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import { CoreComponentsRegistry } from '@singletons/components-registry';
|
import { CoreComponentsRegistry } from '@singletons/components-registry';
|
||||||
import { CorePromisedValue } from '@classes/promised-value';
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "Utils" service with helper functions for UI, DOM elements and HTML code.
|
* "Utils" service with helper functions for UI, DOM elements and HTML code.
|
||||||
|
@ -98,22 +97,20 @@ export class CoreDomUtilsProvider {
|
||||||
* @param element Element to wait.
|
* @param element Element to wait.
|
||||||
* @return Promise resolved when added. It will be rejected after a timeout of 5s.
|
* @return Promise resolved when added. It will be rejected after a timeout of 5s.
|
||||||
*/
|
*/
|
||||||
waitToDom(
|
async waitToBeInDOM(
|
||||||
element: Element,
|
element: Element,
|
||||||
): CorePromisedValue<void> {
|
): Promise<void> {
|
||||||
let root = element.getRootNode({ composed: true });
|
let root = element.getRootNode({ composed: true });
|
||||||
const inDomPromise = new CorePromisedValue<void>();
|
|
||||||
|
|
||||||
if (root === document) {
|
if (root === document) {
|
||||||
// Already in DOM.
|
// Already in DOM.
|
||||||
inDomPromise.resolve();
|
return;
|
||||||
|
|
||||||
return inDomPromise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
// Disconnect observer for performance reasons.
|
// Disconnect observer for performance reasons.
|
||||||
const timeout = window.setTimeout(() => {
|
const timeout = window.setTimeout(() => {
|
||||||
inDomPromise.reject(new Error('Waiting for DOM timeout reached'));
|
reject(new Error('Waiting for DOM timeout reached'));
|
||||||
observer.disconnect();
|
observer.disconnect();
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
|
@ -122,13 +119,12 @@ export class CoreDomUtilsProvider {
|
||||||
if (root === document) {
|
if (root === document) {
|
||||||
observer.disconnect();
|
observer.disconnect();
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
inDomPromise.resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
observer.observe(document.body, { subtree: true, childList: true });
|
observer.observe(document.body, { subtree: true, childList: true });
|
||||||
|
});
|
||||||
return inDomPromise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,7 +135,7 @@ export class CoreDomUtilsProvider {
|
||||||
* @param element DOM Element.
|
* @param element DOM Element.
|
||||||
* @param selector Selector to search.
|
* @param selector Selector to search.
|
||||||
* @return Closest ancestor.
|
* @return Closest ancestor.
|
||||||
* @deprecated Not needed anymore since it's supported on both Android and iOS. Use closest instead.
|
* @deprecated since app 4.0 Not needed anymore since it's supported on both Android and iOS. Use closest instead.
|
||||||
*/
|
*/
|
||||||
closest(element: Element | undefined | null, selector: string): Element | null {
|
closest(element: Element | undefined | null, selector: string): Element | null {
|
||||||
return element?.closest(selector) ?? null;
|
return element?.closest(selector) ?? null;
|
||||||
|
|
Loading…
Reference in New Issue