Skip to content

Instantly share code, notes, and snippets.

@drufball
Created August 28, 2017 21:53
Show Gist options
  • Save drufball/f31176380109e83766706f9eea904881 to your computer and use it in GitHub Desktop.
Save drufball/f31176380109e83766706f9eea904881 to your computer and use it in GitHub Desktop.
Combining lit-html with Polymer3
import { render as litRender } from 'lit-html/lit-html.js'
export const LitMixin = (superClass) => class extends superClass{
static get properties() { return {} }
static get observers() {
const props = Object.keys(this.properties)
if( props.length == 0 ) { return [] }
return [`_litUpdate(${props.join(",")})`]
}
static get template() {
return `
<div id="root"></div>
`;
}
connectedCallback() {
super.connectedCallback();
const props = Object.keys(this.constructor.properties);
if( props.length != 0 ) {
this._createMethodObserver(this.constructor.observers[0], true);
}
this._litUpdate()
}
_litUpdate() {
litRender(this.render(), this.$.root);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment