Now, update the view when the rating attribute changes; this is similar to an input updating its view when you set <input value="newValue">. Luckily, the web component lifecycle includes the attributeChangedCallback. Update the rating by adding the following lines:
In order for the attributeChangedCallback to trigger, you must set a static getter for RatingElement.observedAttributes which declares which attributes should be observed for changes. You then set the rating attribute declaratively in the DOM. Give it a try: