git » hoplite.git » commit a33348b

entities remove

author Alan Dipert
2021-05-29 05:54:08 UTC
committer Alan Dipert
2021-05-29 05:54:08 UTC
parent 0169179c555a55e71cb1c4659f0c25ed4d924ef9

entities remove

datalog.mjs +1 -1
el.mjs +5 -1
todo.mjs +28 -13

diff --git a/datalog.mjs b/datalog.mjs
index cdd4744..9b53075 100644
--- a/datalog.mjs
+++ b/datalog.mjs
@@ -213,7 +213,7 @@ function partialQuery(q) {
   return (...vals) => query(q, ...vals);
 }
 
-export { _, query, TupleSet, partialQuery };
+export { ANY, _, query, TupleSet, partialQuery };
 // let db = new JSONSet([
 //   ["sally", "age", 21],
 //   ["fred", "age", 42],
diff --git a/el.mjs b/el.mjs
index c1a622e..d128b13 100644
--- a/el.mjs
+++ b/el.mjs
@@ -84,11 +84,14 @@ class EntityNodes {
     this.makeNode = makeNode;
     this.pool = [];
     this.nodeToEidCell = new Map();
+    this.eidToNode = new Map();
     this.bufferedCommands = [];
     this.callback = command => this.bufferedCommands.push(command);
     watch((added, removed) => {
       for (let [eid] of removed) {
-        // TODO
+        let node = this.eidToNode.get(eid);
+        this.eidToNode.delete(eid);
+        this.callback([Node.prototype.removeChild, node]);
       }
       for (let [eid] of added) {
         let node;
@@ -99,6 +102,7 @@ class EntityNodes {
           let eidCell = input(eid),
               attrs = makeAttrCells(db, eidCell);
           node = this.makeNode(attrs);
+          this.eidToNode.set(eid, node);
           this.nodeToEidCell.set(node, eidCell);
         }
         this.callback([Node.prototype.appendChild, node]);
diff --git a/todo.mjs b/todo.mjs
index 8d9f025..e547a7e 100644
--- a/todo.mjs
+++ b/todo.mjs
@@ -1,5 +1,5 @@
-import { query, _ } from './datalog.mjs';
-import { transaction, input, formula, database, view, watch } from './reactives.mjs';
+import { query, _, ANY } from './datalog.mjs';
+import { input, database, view } from './reactives.mjs';
 import { $el, on, entities } from './el.mjs';
 
 let todos = database([
@@ -11,14 +11,33 @@ let todos = database([
   [2, "status", "done"]
 ]);
 
-function todoList(todos) {
-  return $el.ul(
-    entities(todos, attrs => $el.li(
-      attrs.text
-    ))
-  )
-}
+let showStatus = input(ANY.VALUE);
 
+let visibleTodos = view({
+  find: [_.eid, _.attr, _.val],
+  use: [_.status],
+  where: [
+    [_.eid, "status", _.status],
+    [_.eid, _.attr, _.val]
+  ]
+})(todos, showStatus);
+
+let todoList = $el.ul(
+  $el.select({
+    [on.change]: ({target: {value}}) => {
+      showStatus.set(value === "any" ? ANY.VALUE : value)
+    }
+  },
+    $el.option({value: "any"}, "Any"),
+    $el.option({value: "ready"}, "Ready"),
+    $el.option({value: "done"}, "Done")
+  ),
+  entities(visibleTodos, attrs => $el.li(attrs.text))
+);
+
+document.addEventListener("DOMContentLoaded", () => {
+  document.body.appendChild(todoList);
+});
 // function nextEid(db) {
 //   return ([...db].map(([eid]) => eid).sort((x, y) => y - x)[0] || 0) + 1; 
 // }
@@ -83,10 +102,6 @@ function todoList(todos) {
 //   );
 // }
 
-document.addEventListener("DOMContentLoaded", () => {
-  document.body.appendChild(todoList(todos));
-});
-
 // window.todos = todos;
 
 // class TodoItem {