- From: Mark Kennedy <notifications@github.com>
- Date: Sun, 14 Oct 2018 06:48:34 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Sunday, 14 October 2018 13:48:55 UTC
I couldn't find any information in the spec about whether `connectedCallback` and `disconnectedCallback` lifecycle hooks support promises or not. But I'd like to do things asynchronously before a component is removed from the DOM. Let's assume I have a custom element that represents a page within my application. I'd like to be able to fade the page out before it disconnects.
```js
 class MyPage extends HTMLElement {
    async disconnectedCallback() {
        const animation = this.animate([
                { opacity: 1},
                { opacity: 0},
            ],
            {
                duration: 1500,
                fill: 'forwards',
            });
        return animation.finished;
    }
  }
```
As of right now, when the element is removed from the DOM, it does not wait for the promise I'm returning, so the fade out never happens.
Here is a working example:
https://stackblitz.com/edit/async-callbacks
-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/705
Received on Sunday, 14 October 2018 13:48:55 UTC