Event Listeners

Permalink to "Event Listeners"

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:

rating-element.

Permalink to "rating-element."

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.

You can learn more about the Lit binding syntax in the Lit Expressions documentation.

Next:

rating-element.

Permalink to "rating-element."

You were able to remove:

Rendering Property Updates

Permalink to "Rendering Property Updates"

Finally, update the property setters to utilize the render method so that the DOM can update when either the properties or attributes change:

rating-element.

Permalink to "rating-element."

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:

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!

Thumb up and down rating slider with a value of 6 and the up thumb colored green