|
| 1 | +// Direct JSX file, no framework — runs with your runtime |
| 2 | +import { signal, effect } from "../runtime/signals.js" |
| 3 | +import { insert, createElement } from "../runtime/dom.js" |
| 4 | + |
| 5 | +// Core signals |
| 6 | +const todos = signal([]) |
| 7 | +const filter = signal("all") |
| 8 | +const input = signal("") |
| 9 | + |
| 10 | +// Add 10,000 todos initially |
| 11 | +for (let i = 0; i < 10000; i++) { |
| 12 | + todos.value.push({ id: i, text: `Task #${i}`, done: false }) |
| 13 | +} |
| 14 | + |
| 15 | +// Reactive rendering |
| 16 | +effect(() => { |
| 17 | + const root = document.getElementById("app") |
| 18 | + root.innerHTML = "" |
| 19 | + |
| 20 | + const visible = todos.value.filter(todo => { |
| 21 | + if (filter.value === "done") return todo.done |
| 22 | + if (filter.value === "active") return !todo.done |
| 23 | + return true |
| 24 | + }) |
| 25 | + |
| 26 | + for (const todo of visible) { |
| 27 | + const div = createElement("div") |
| 28 | + div.className = "todo" |
| 29 | + div.style.padding = "2px" |
| 30 | + div.style.borderBottom = "1px solid #eee" |
| 31 | + div.onclick = () => { |
| 32 | + todo.done = !todo.done |
| 33 | + todos.value = [...todos.value] // trigger update |
| 34 | + } |
| 35 | + div.textContent = `${todo.done ? "✅" : "⬜️"} ${todo.text}` |
| 36 | + insert(root, div) |
| 37 | + } |
| 38 | +}) |
| 39 | + |
| 40 | +// Input UI |
| 41 | +window.onload = () => { |
| 42 | + const inputBox = document.getElementById("input") as HTMLInputElement |
| 43 | + const filterAll = document.getElementById("filter-all") |
| 44 | + const filterDone = document.getElementById("filter-done") |
| 45 | + const filterActive = document.getElementById("filter-active") |
| 46 | + const addButton = document.getElementById("add") |
| 47 | + |
| 48 | + inputBox.oninput = (e) => input.value = (e.target as HTMLInputElement).value |
| 49 | + addButton.onclick = () => { |
| 50 | + if (!input.value.trim()) return |
| 51 | + todos.value = [ |
| 52 | + ...todos.value, |
| 53 | + { id: todos.value.length, text: input.value, done: false } |
| 54 | + ] |
| 55 | + input.value = "" |
| 56 | + inputBox.value = "" |
| 57 | + } |
| 58 | + |
| 59 | + filterAll.onclick = () => filter.value = "all" |
| 60 | + filterDone.onclick = () => filter.value = "done" |
| 61 | + filterActive.onclick = () => filter.value = "active" |
| 62 | +} |
0 commit comments