feat: only call onChanges when previousValue !== currentValue

This commit is contained in:
Ayo 2023-09-17 13:48:57 +02:00
parent 8cfd286598
commit 0ba7738da1
2 changed files with 5 additions and 2 deletions

View file

@ -23,10 +23,9 @@ export class WebComponent extends HTMLElement {
attributeChangedCallback(property, previousValue, currentValue) { attributeChangedCallback(property, previousValue, currentValue) {
if (previousValue !== currentValue) { if (previousValue !== currentValue) {
this[property] = currentValue; this[property] = currentValue;
this.onChanges({ property, previousValue, currentValue });
this.render(); this.render();
} }
this.onChanges({ property, previousValue, currentValue });
} }
render() { render() {

View file

@ -16,6 +16,10 @@
setTimeout(() => { setTimeout(() => {
helloWorld.setAttribute("emotion", "excited"); helloWorld.setAttribute("emotion", "excited");
}, 2500); }, 2500);
helloWorld.addEventListener("click", () => {
helloWorld.setAttribute("name", "Clicked");
});
</script> </script>
</body> </body>
</html> </html>