@virtualstate/examples
Version:
48 lines • 1.78 kB
JavaScript
import { h, createToken } from "@virtualstate/fringe";
async function* eventListener(that, event) {
}
const ValueUpdateSymbol = Symbol("ValueUpdate");
const ValueUpdate = createToken(ValueUpdateSymbol);
async function* WatchValue() {
for await (const event of eventListener(this, "input")) {
yield h(ValueUpdate, { value: this.value, id: this.id });
}
}
const example = (h("form", null,
h("input", { type: "text", value: "" },
h(WatchValue, null))));
const example2 = (h("form", {}, h("input", { type: "text", value: "", id: "something" }, h(WatchValue))));
const typed = example2;
async function* render(hasUser) {
const form = document.createElement(typed.source);
document.getElementById("root").append(form);
for await (const elements of typed.children) {
for (const element of elements) {
const input = document.createElement(element.source);
form.append(input);
/* set some attributes here */
const yielding = [];
if (element.source === "input") {
if (hasUser) {
for await (const processors of element.children) {
yielding.push(h(processors.map(processor => ({
...processor,
source: processor.source.bind(input)
}))));
}
}
}
yield yielding;
}
}
}
async function exampleRun() {
for await (const events of h(render(true)).children) {
for (const event of events) {
if (ValueUpdate.is(event)) {
console.log({ [event.options.id]: event.options.value });
}
}
}
}
//# sourceMappingURL=index.js.map