import { LitElement, html } from 'lit' import { until } from 'lit/directives/until.js' import { unsafeHTML } from 'lit-html/directives/unsafe-html.js' export class DisplayFeed extends LitElement { static get properties () { return { max: { type: Boolean }, posts: { type: Array, state: true }, feed: { type: String }, title: { type: String } } } constructor () { super() this.title = 'Display Feed' } _post (post) { return html`

${post.title}

${unsafeHTML(post.content)}
` } // connectedCallback () { // super.connectedCallback() // console.error // this.posts = fetch(this.feed) // .then(async res => { // const posts = await res.json() // return posts.posts.map(this._post) // }) // } updated (changedProperties) { console.error('dentro changed ', changedProperties) console.error(this.feed) console.error(changedProperties) if (changedProperties.has('feed')) { console.error('feed cambiato') this.posts = fetch(this.feed) .then(async res => { const posts = await res.json() return posts.posts.map(this._post) }) } } render() { // const loading = html`Loading...` // const title = html`

${this.title}

` return html`

${this.title}

${until(this.posts, 'Loading...')}` } // do not create a shadowDOM (we want style pollution from outside) createRenderRoot() { return this } } customElements.define('display-feed', DisplayFeed)