Skip to content

Instantly share code, notes, and snippets.

@TravisMullen
Created June 8, 2018 22:04
Show Gist options
  • Save TravisMullen/2c4f465bde64fcc88df4538a9608cb55 to your computer and use it in GitHub Desktop.
Save TravisMullen/2c4f465bde64fcc88df4538a9608cb55 to your computer and use it in GitHub Desktop.
Example: Lit Element's Repeat Method
<html>
<head>
<!-- Polyfills only needed for Firefox and Edge. -->
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@next/webcomponents-loader.js"></script>
</head>
<body>
<!-- Works only on browsers that support Javascript modules like
Chrome, Safari, Firefox 60, Edge 17 -->
<script type="module">
import { LitElement, html } from 'https://unpkg.com/@polymer/lit-element@latest/lit-element.js?module';
import { repeat } from 'https://unpkg.com/lit-html@latest/lib/repeat.js?module';
class ListJawn extends LitElement {
static get properties() {
return {
collection: Array
}
}
constructor() {
super();
this.collection = [
{ color: 'yellow', name: 'Saturn', order: 2, target: '#Saturn' },
{ color: 'green', name: 'Jupiter', order: 3, target: '#Jupiter' }
];
}
_render({ collection }) {
return html`
<ul>
${repeat(
collection,
(item, index) => html`<li>${item.name}</li>`
)}
</ul>
`
}
}
customElements.define('my-list', ListJawn);
</script>
<my-list></my-list>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment