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