github.com/andrewbeng89
andrewbeng89.me
andrew@factorial.io
import { reactive, effect } from
"https://unpkg.com/@vue/reactivity?module";
const state = reactive({
count: 0
});
effect(() => {
console.log(state.count);
// 0
// 1
});
const add = () => state.count++;
add();
... published as a package that can be used standalone
export default ({ name, setup, props }) => {
customElements.define(
name,
class extends HTMLElement {
static get observedAttributes() {
// Return a list of observed attribute names
}
constructor() {
// 1. Scaffold reactive props
// 2. Scaffold slots as reactive object
// 3. Apply effect to render the template + run hooks
}
connectedCallback() {
// 1. Run beforeMount hook
// 2. Render template + invoke setup()
// 3. Run mounted hook
// 4. Bind template slots to reactive object
// 5. Validate props
}
disconnectedCallback() {
// Run unmounted hook
}
attributeChangedCallback() {
// Parse, validate and update reactive props
}
}
);
}
import { defineComponent, reactive, html }
from "https://unpkg.com/vue-uhtml?module";
defineComponent({
name: "my-component",
setup: () => {
const state = reactive({
text: "hello"
});
const onInput = (e) => {
state.text = e.target.value;
};
return () => html`
<p>
<input value=${state.text} oninput=${onInput} />
<span>${state.text}</span>
</p>
`;
},
});
<my-component></my-component>