-
-
Save peschee/e29ffde2173ef42fa6184efa5d57db2a to your computer and use it in GitHub Desktop.
updateSubtreeComplete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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