all repos — h3 @ 584bff33c98e23f19eec9759b40f65e41bbaa4d2

A tiny, extremely minimalist JavaScript microframework.

Refactoring - update method.
h3rald h3rald@h3rald.com
Mon, 13 Apr 2020 22:19:52 +0200
commit

584bff33c98e23f19eec9759b40f65e41bbaa4d2

parent

27341c470a6e198ec42dc525683381285d76fd00

M example/assets/js/components/addTodoForm.jsexample/assets/js/components/addTodoForm.js

@@ -5,7 +5,7 @@ const addTodo = () => {

const newTodo = document.getElementById("new-todo"); if (!newTodo.value) { h3.dispatch("error/set"); - h3.dispatch("$update"); + h3.update() document.getElementById("new-todo").focus(); return; }

@@ -15,7 +15,7 @@ key: `todo_${Date.now()}__${newTodo.value}`, // Make todos "unique-enough" to ensure they are processed correctly

text: newTodo.value, }); newTodo.value = ""; - h3.dispatch("$update"); + h3.update() document.getElementById("new-todo").focus(); }; const addTodoOnEnter = (event) => {
M example/assets/js/components/navigationBar.jsexample/assets/js/components/navigationBar.js

@@ -6,7 +6,7 @@ // Set the todo filter.

const setFilter = () => { let f = document.getElementById("filter-text"); h3.dispatch("todos/filter", f.value); - h3.dispatch("$update"); + h3.update() f = document.getElementById("filter-text"); f.focus(); };
M example/assets/js/components/paginator.jsexample/assets/js/components/paginator.js

@@ -18,14 +18,14 @@ const page = h3.state('page');

const newPage = page - 1; h3.dispatch("pages/set", newPage); window.location.hash = `/?page=${newPage}`; - h3.dispatch("$update"); + h3.update() } function setNextPage() { const page = h3.state('page'); const newPage = page + 1; h3.dispatch("pages/set", newPage); window.location.hash = `/?page=${newPage}`; - h3.dispatch("$update"); + h3.update() } return h3("div.paginator", [ h3(
M example/assets/js/components/todo.jsexample/assets/js/components/todo.js

@@ -4,11 +4,11 @@ export default function Todo(data) {

const todoStateClass = data.done ? ".done" : ".todo"; const toggleTodo = (todo) => { h3.dispatch("todos/toggle", data); - h3.dispatch("$update"); + h3.update() }; const removeTodo = (todo) => { h3.dispatch("todos/remove", data); - h3.dispatch("$update"); + h3.update() }; return h3(`div#${data.key}.todo-item`, [ h3(`div.todo-content${todoStateClass}`, [
M h3.jsh3.js

@@ -292,7 +292,7 @@ this.state = {};

} dispatch(event, data) { if (this.events[event]) { - if (event !== "log") this.dispatch("log", { event, data }); + if (event !== "$log") this.dispatch("$log", { event, data }); let changes = {}; let changed; this.events[event].forEach((i) => {

@@ -313,16 +313,6 @@ this.events[event] = this.events[event].filter((i) => i !== cb);

}; } } - -const createStore = (modules) => { - const store = new Store(); - - modules.forEach((i) => { - if (i) i(store); - }); - - return store; -}; class Route { constructor({ path, def, query, parts, fallback }) {

@@ -439,7 +429,6 @@ // Initialize router

//router = new Router({element, routes}) // Render //router.start(); - store.on('$update', updateFn); element.appendChild(vnode.render()); }