all repos — h3 @ 5e31908950c15af54b2b872059921f906c762fb9

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
 22
 23
export default function Todo() {
  return function (data) {
    const self = this;
    self.app = data.app;
    self.view = (h3, data) => {
      const todoStateClass = data.done ? ".done" : ".todo";
      function toggle() {
        data.done = !data.done;
        self.app.redraw();
      }
      function remove() {
        self.app.todos = self.app.todos.filter(({ key }) => key !== data.key);
        self.app.redraw();
      }
      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 }),
      ]);
    };
  };
}