Skip to content

Instantly share code, notes, and snippets.

@bengfarrell
Created September 6, 2019 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bengfarrell/0056a79751a9a63073b23e18682e7f74 to your computer and use it in GitHub Desktop.
Save bengfarrell/0056a79751a9a63073b23e18682e7f74 to your computer and use it in GitHub Desktop.
LitElement not updating
import { LitElement, html } from 'lit-element';
class SimpleGreeting extends LitElement {
constructor() {
super();
this.model = {
currentThing: 'optionA',
things: [ 'optionA', 'optionB' ]
};
}
onSelect(e) {
this.model.currentThing = e.target.value;
this.render();
}
render(){
return html`<select @change=${e => this.onSelect(e)}>
${this.model.things.map(thing =>
html`<option value="${thing}">${thing}</option>` )}
</select>
<div>
${this.displaySelected()}
</div>`;
}
displaySelected() {
switch(this.model.currentThing) {
case 'optionA': return html`<span>A_A_A_A_A_A</span>`;
case 'optionB': return html`<span>B_B_B_B_B_B</span>`;
}
}
}
customElements.define('simple-greeting', SimpleGreeting);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment