UNPKG

@blackglory/wait-for

Version:

A module for waiting for things to happen.

20 lines (16 loc) 544 B
import { observeRemovalsOfDescendantNodes } from '@blackglory/observe' import { firstValueFrom } from 'rxjs' import { filter } from 'rxjs/operators' export async function waitForAllElementsMatchingSelectorDetached( selector: string ): Promise<void> { if (countElements(selector) === 0) return await firstValueFrom( observeRemovalsOfDescendantNodes(document).pipe( filter(() => countElements(selector) === 0) ) ) } function countElements(selector: string): number { return document.querySelectorAll(selector).length }