Skip to content

Instantly share code, notes, and snippets.

@peschee
Forked from sorvell/updateSubtreeComplete.js
Created May 17, 2021 06:17
Show Gist options
  • Save peschee/e29ffde2173ef42fa6184efa5d57db2a to your computer and use it in GitHub Desktop.
Save peschee/e29ffde2173ef42fa6184efa5d57db2a to your computer and use it in GitHub Desktop.
updateSubtreeComplete
class MyElement extends LitElement {
// Promise that will resolve when the entire subtree of the element's `renderRoot` has finished updating/rendering.
get updateSubtreeComplete() {
async function awaitSubtree(el) {
await el.updateComplete;
const clients = el.renderRoot!.querySelectorAll('*');
await Promise.all(Array.from(clients).map((e) =>
e.updateSubtreeComplete || awaitSubtree(e as UpdatingElement)));
}
return awaitSubtree(this);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment