1import { html, state, effect, repeat } from '@beforesemicolon/markup';2 3const [todos, setTodos] = state(4 JSON.parse(localStorage.getItem('todos') ?? '[]')5);6const [draft, setDraft] = state('');7 89effect(() => {10 localStorage.setItem('todos', JSON.stringify(todos()));11});12 13const addTodo = () => {14 if (!draft().trim()) return;15 setTodos([...todos(), { text: draft(), done: false }]);16 setDraft('');17};18 19const toggle = (i) =>20 setTodos(todos().map((t, idx) =>21 idx === i ? { ...t, done: !t.done } : t22 ));23 24html`25 <input26 value="${draft}"27 oninput="${(e) => setDraft(e.target.value)}"28 placeholder="What needs doing?"29 />30 <button type="button" onclick="${addTodo}">Add</button>31 32 <ul>33 ${repeat(todos, (todo, i) => html`34 <li class="${() => todo.done ? 'done' : ''}"35 onclick="${() => toggle(i)}">36 ${todo.text}37 </li>38 `)}39 </ul>40`.render(document.querySelector('#app'));