Created
December 18, 2018 00:15
-
-
Save sorvell/81b4bafbccd140875507f4dc1dbca490 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