all repos — h3 @ 25dfab636dbe8070597e23bdc5d2f678aea307db

A tiny, extremely minimalist JavaScript microframework.

example/assets/js/components/todo.js

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
import h3 from "../h3.js";
import store from "../store.js";

export default function Todo(data) {
  const todoStateClass = data.done ? ".done" : ".todo";
  const toggleTodo = (todo) => {
    store.dispatch("todos/toggle", data);
    store.dispatch("$update");
  };
  const removeTodo = (todo) => {
    store.dispatch("todos/remove", data);
    store.dispatch("$update");
  };
  return h3(`div#${data.key}.todo-item`, [
    h3(`div.todo-content${todoStateClass}`, [
      h3("span.todo-text", { onclick: () => toggleTodo(data) }, data.text),
    ]),
    h3("span.delete-todo", { onclick: () => removeTodo(data) }, "✘"),
  ]);
}