On generator functions for skeleton screens #84
|
The Getting started section from the docs states that a component class can be declared as an asynchronous generator. The I am curious about the usage of generator functions along with Tonic to display skeleton screens for web components. Can anyone elaborate further how would such a component be called? Or, better, complete the docs with a working example. |
Replies: 1 comment 3 replies
|
Yeah the docs could use some more materials in this area. Roughly (I haven't run this code), you could add your top level component and a it can have a child component with an async-generator renderer like this... class MyAsyncComponent extends Tonic {
click () {
this.reRender()
}
async * render () {
yield this.html`<tonic-loader></tonic-loader>`
const data = await foobar()
return this.html`
<div>${data}</div>
`
}
}
class AppContainer extends Tonic {
render () {
return this.html`
<div>
<my-async-component></my-async-component>
</div>
`
}
}
Tonic.add(MyAsyncComponent)
Tonic.add(AppContainer)
document.addEventListener('DOMContentLoaded', () => {
document.body.appendChild(new AppContainer())
}) |
Yeah the docs could use some more materials in this area. Roughly (I haven't run this code), you could add your top level component and a it can have a child component with an async-generator renderer like this...