Skip to content

Instantly share code, notes, and snippets.

@alandipert
Last active June 2, 2021 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandipert/ce0fa7dcb6cd74c4f5ea6679fe29dce1 to your computer and use it in GitHub Desktop.
Save alandipert/ce0fa7dcb6cd74c4f5ea6679fe29dce1 to your computer and use it in GitHub Desktop.
import { query, _, ANY, paths } from './datalog.mjs';
import { input, formula, database, view } from './reactives.mjs';
import { $el, entities } from './el.mjs';
let todos = database(paths([
{text: "do the thing", status: "ready"},
{text: "do the other thing", status: "ready"},
{text: "do that last thing", status: "done"}
]));
let showStatus = input(ANY.VALUE);
let visibleTodos = view({
find: [_.e, _.a, _.v],
use: [_.status],
where: [
[_.e, "status", _.status],
[_.e, _.a, _.v]
]
})(todos, showStatus);
let todoList = $el.ul(
$el.select({
onchange: ({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(
formula((eid, text) => `${eid} - ${text}`)(attrs._eid, attrs.text)
))
);
document.addEventListener("DOMContentLoaded", () => {
document.body.appendChild(todoList);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment