1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-22 16:55:23 +01:00
deka-dom-el/test/index.js

55 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-08-25 12:04:15 +02:00
import { S, watch, el, namespace, assign, on, dispatch } from "../index.js";
Object.assign(globalThis, { S, watch, el, namespace, assign, on, dispatch });
2023-08-22 16:30:03 +02:00
const { style, css }= createStyle();
globalThis.test= console.log;
2023-08-25 12:04:15 +02:00
const app= el(component, null, on("change", globalThis.test));
dispatch("change", "Peter")(app);
console.log(app, app instanceof HTMLDivElement);
2023-08-22 16:30:03 +02:00
document.head.append(style);
document.body.append(app);
function component({ name= "World", surname= "" }= {}){
const className= "naiveForm";
css`
.${className}{
display: flex;
flex-flow: column nowrap;
}
.${className} input{
margin-inline-start: .5em;
}
`;
const store= S({ name, surname });
const full_name= S(()=> store.name()+" "+store.surname());
2023-08-25 12:04:15 +02:00
on(full_name, console.log);
return el("div", { className }, on.connected(console.log)).append(
el("p").append(
el("#text", { textContent: "Hello " }),
el("strong", { textContent: full_name }),
el("#text", { textContent: "!" }),
),
el("label").append(
el("#text", { textContent: "Set name:" }),
el("input", { type: "text", value: store.name },
2023-08-25 12:04:15 +02:00
on("change", ev=> store.name(ev.target.value))),
),
el("label").append(
el("#text", { textContent: "Set surname:" }),
el("input", { type: "text", value: store.surname },
2023-08-25 12:04:15 +02:00
on("change", ev=> store.surname(ev.target.value))),
)
2023-08-22 16:30:03 +02:00
)
}
function createStyle(){
const style= el("style");
return {
style,
css(...args){
style.appendChild(el("#text", { textContent: String.raw(...args) }));
}
};
}