Re: [w3c/webcomponents] A way to detect if a custom element was constructed during customElements.define call? (#790)

I made a module to detect it:

```js
export var isCustomElementsDefineCall = false

const oldDefine = customElements.define

customElements.define = function(tagName, Constructor) {
    isCustomElementsDefineCall = true
    oldDefine.call(this, tagName, Constructor)
    isCustomElementsDefineCall = false
}
```

So then,

```js
import { isCustomElementsDefineCall } from './util/isCustomElementsDefineCall'

class MyEl extends HTMLElement {
 constructor() {
  if (isCustomElementsDefineCall) {
    console.log('created during customElementas.define call')
  }
 }
}
```

now when I detect this case, I can schedule an observation of children.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/790#issuecomment-460923302

Received on Wednesday, 6 February 2019 07:15:23 UTC