all repos — h3 @ 445a314facea9c5e0d92f13ab4c88708e09d87db

A tiny, extremely minimalist JavaScript microframework.

example/assets/js/todo.js

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

export default function Todo(app) {
  return function(data) {
    const todoStateClass = data.done ? ".done" : ".todo";
    function toggle() {
      data.done = !data.done;
      app.update();
    }
    function remove() {
      app.todos = app.todos.filter(({ key }) => key !== data.key);
      app.update();
    }
    return h3("div.todo-item", { id: data.key }, [
      h3(`div.todo-content${todoStateClass}`, [
        h3("span.todo-text", { onclick: toggle }, [data.text]),
      ]),
      h3("span.delete-todo.fas.fa-trash", { onclick: remove }),
    ]);
  };
}