import { input, database, transaction } from './reactives.mjs';
import { h, entities } from './el.mjs';
function todoList() {
let todos = database([]),
newTodo = input("");
return h.div(
h.h3("TODO"),
h.input({
type: "text",
value: newTodo,
onchange: ({target: {value}}) => newTodo.set(value)
}),
h.input({
type: "button",
value: "Add",
onclick: () => transaction(() => {
todos.add([
[todos.maxEid + 1, "text", newTodo.value]
]);
newTodo.set("");
})
}),
h.ul(
entities(todos, "_eid", "asc", attrs => h.li(attrs.text))
)
)
}
document.addEventListener("DOMContentLoaded", () => {
document.body.appendChild(todoList());
});