Skip to content

Instantly share code, notes, and snippets.

@UpperCod
Last active February 11, 2021 03:33
Show Gist options
  • Save UpperCod/df54b2c50eacfea493c359582b15da70 to your computer and use it in GitHub Desktop.
Save UpperCod/df54b2c50eacfea493c359582b15da70 to your computer and use it in GitHub Desktop.
Reative properties
import { c } from "atomico;
function component() {
return <host></host>;
}
component.props = {
value: String,
checked: {
type: Boolean,
reflect: true,
value : false,
event: { type: "change", bubbles: true, composed: true },
},
};
customElements.define("my-component", c(component));
const myComponent = document.querySelector("my-component");
myComponent.addEventListener("change", ({ target }) => {
console.log(target.checked);
});
// Changes are added to the queue
// update of the webcomponent
myComponent.value = "next value";
myComponent.checked = "next value";
// to read the changes from the DOM we
// must wait for the updated promise to finish
myComponent.updated.then(() => {
console.log("dom update");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment