Skip to content

Instantly share code, notes, and snippets.

@sorvell
Created December 18, 2018 00:15
Show Gist options
  • Save sorvell/81b4bafbccd140875507f4dc1dbca490 to your computer and use it in GitHub Desktop.
Save sorvell/81b4bafbccd140875507f4dc1dbca490 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