Re: [w3c/webcomponents] Lazy Custom Element Definitions (#782)

Currently implementing something very similar to `React.lazy` with Angular's Custom Element API, and I definitely see the value in something along these lines.

A simple primitive that might make this a whole lot easier would be adding the ability to lazily define `observedAttributes` - most everything else can be done in userspace, but they have to be registered up front:

```js
//what i want

const LazyEl = (resolveFn) => class LazyElement extends HTMLElement {
 constructor(){
    super();
     resolveFn().then(impl => {
        impl.default.attrs.forEach((attr) => this.constructor.observeAttribute(attr)); //this doesn't exist :(
     })
  }
}

customElements.define('my-lazy-element', LazyEl(() => import('./my-comp-impl')));
```
```js
//what i have to do
const LazyEl = (resolveFn, attrs) => class LazyElement extends HTMLElement {
 static get observedAttributes(){  return attrs }
 constructor(){
    super();
     resolveFn().then(impl => { ... })
  }
}
customElements.define('my-lazy-element', LazyEl(() => import('./my-comp-impl'), ['foo', 'bar]));
```

-- 
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/782#issuecomment-505651451

Received on Tuesday, 25 June 2019 22:51:52 UTC