Now that you have gotten rid of the <template> element in index.html, refactor the code to take advantage of Lit template features in the newly-defined render() method. You can start by leveraging Lit's event listener binding syntax:
Lit templates can add an event listener to a node with the @EVENT_NAME binding syntax where, in this case, you update the vote property every time these buttons are clicked.
// remove the logic for imperatively setting the innerText
// since it's handled in render()
this.render();
}
...
setvote(newValue) {
...
this._vote=newValue;
this.setAttribute('vote', newValue!);
// call this.render() at the end of the setter
this.render();
}
setrating(value) {
this._rating=value;
// remove the logic for imperatively setting the innerText
// since it's handled in render()
this.render();
}
...
setvote(newValue) {
...
this._vote=newValue;
this.setAttribute('vote', newValue);
// call this.render() at the end of the setter
this.render();
}
This is not the most efficient way to update the DOM.
Synchronously calling render() in the setters of rating and vote is not the most efficient way to update the DOM, but it is a good way to illustrate where LitElement calls render() (next step).
Here, you:
Removed the DOM update logic from the rating setter.
Added a call to render from the vote setter.
Now the template is much more readable as you now can see where the bindings and event listeners are applied.
You should have a functioning <rating-button> that should look like this when the upvote is pressed!