mirror of
https://github.com/morris/vanilla-todo.git
synced 2025-08-14 01:54:08 +02:00
rename store to controller, update data flow section
This commit is contained in:
15
README.md
15
README.md
@@ -351,8 +351,16 @@ however exclusively using custom DOM events.
|
|||||||
usually resulting in some parent component state change which is in turn
|
usually resulting in some parent component state change which is in turn
|
||||||
propagated downwards through data events.
|
propagated downwards through data events.
|
||||||
|
|
||||||
The data store is factored into a separate behavior (`TodoStore`).
|
The business logic is factored into a pure functional core
|
||||||
It only receives and dispatches events and encapsulates all of the data logic.
|
([TodoLogic.js](./public/scripts/TodoLogic.js)).
|
||||||
|
This is a good idea in many UI architectures as it encapsulates
|
||||||
|
state transitions in a portable, testable unit.
|
||||||
|
|
||||||
|
The controller is factored into a separate behavior
|
||||||
|
([TodoController.js](./public/scripts/TodoController.js)).
|
||||||
|
It only receives and dispatches events,
|
||||||
|
calling the business logic to apply changes and emit state.
|
||||||
|
It also handles persistence in Local Storage.
|
||||||
|
|
||||||
Listening to and dispatching events is slightly verbose with standard APIs and
|
Listening to and dispatching events is slightly verbose with standard APIs and
|
||||||
certainly justifies introducing helpers.
|
certainly justifies introducing helpers.
|
||||||
@@ -363,7 +371,8 @@ concisely with standard APIs.
|
|||||||
Reference:
|
Reference:
|
||||||
|
|
||||||
- [TodoDay.js](./public/scripts/TodoDay.js)
|
- [TodoDay.js](./public/scripts/TodoDay.js)
|
||||||
- [TodoStore.js](./public/scripts/TodoStore.js)
|
- [TodoController.js](./public/scripts/TodoController.js)
|
||||||
|
- [TodoLogic.js](./public/scripts/TodoLogic.js)
|
||||||
|
|
||||||
#### 3.2.3. Rendering
|
#### 3.2.3. Rendering
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
<link rel="modulepreload" href="scripts/AppIcon.js" />
|
<link rel="modulepreload" href="scripts/AppIcon.js" />
|
||||||
<link rel="modulepreload" href="scripts/AppSortable.js" />
|
<link rel="modulepreload" href="scripts/AppSortable.js" />
|
||||||
<link rel="modulepreload" href="scripts/TodoApp.js" />
|
<link rel="modulepreload" href="scripts/TodoApp.js" />
|
||||||
|
<link rel="modulepreload" href="scripts/TodoController.js" />
|
||||||
<link rel="modulepreload" href="scripts/TodoCustomList.js" />
|
<link rel="modulepreload" href="scripts/TodoCustomList.js" />
|
||||||
<link rel="modulepreload" href="scripts/TodoDay.js" />
|
<link rel="modulepreload" href="scripts/TodoDay.js" />
|
||||||
<link rel="modulepreload" href="scripts/TodoFrameCustom.js" />
|
<link rel="modulepreload" href="scripts/TodoFrameCustom.js" />
|
||||||
@@ -25,8 +26,9 @@
|
|||||||
<link rel="modulepreload" href="scripts/TodoItem.js" />
|
<link rel="modulepreload" href="scripts/TodoItem.js" />
|
||||||
<link rel="modulepreload" href="scripts/TodoItemInput.js" />
|
<link rel="modulepreload" href="scripts/TodoItemInput.js" />
|
||||||
<link rel="modulepreload" href="scripts/TodoList.js" />
|
<link rel="modulepreload" href="scripts/TodoList.js" />
|
||||||
<link rel="modulepreload" href="scripts/TodoStore.js" />
|
<link rel="modulepreload" href="scripts/TodoLogic.js" />
|
||||||
<link rel="modulepreload" href="scripts/util.js" />
|
<link rel="modulepreload" href="scripts/util.js" />
|
||||||
|
<link rel="modulepreload" href="scripts/uuid.js" />
|
||||||
|
|
||||||
<link rel="stylesheet" href="styles/base.css" />
|
<link rel="stylesheet" href="styles/base.css" />
|
||||||
<link rel="stylesheet" href="styles/app-button.css" />
|
<link rel="stylesheet" href="styles/app-button.css" />
|
||||||
|
@@ -2,10 +2,10 @@ import { AppCollapsible } from './AppCollapsible.js';
|
|||||||
import { AppFlip } from './AppFlip.js';
|
import { AppFlip } from './AppFlip.js';
|
||||||
import { AppFps } from './AppFps.js';
|
import { AppFps } from './AppFps.js';
|
||||||
import { AppIcon } from './AppIcon.js';
|
import { AppIcon } from './AppIcon.js';
|
||||||
|
import { TodoController } from './TodoController.js';
|
||||||
import { TodoFrameCustom } from './TodoFrameCustom.js';
|
import { TodoFrameCustom } from './TodoFrameCustom.js';
|
||||||
import { TodoFrameDays } from './TodoFrameDays.js';
|
import { TodoFrameDays } from './TodoFrameDays.js';
|
||||||
import { TodoLogic } from './TodoLogic.js';
|
import { TodoLogic } from './TodoLogic.js';
|
||||||
import { TodoStore } from './TodoStore.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {HTMLElement} el
|
* @param {HTMLElement} el
|
||||||
@@ -43,7 +43,7 @@ export function TodoApp(el) {
|
|||||||
removeTimeout: 200,
|
removeTimeout: 200,
|
||||||
});
|
});
|
||||||
|
|
||||||
TodoStore(el);
|
TodoController(el);
|
||||||
|
|
||||||
el.querySelectorAll('.app-collapsible').forEach(AppCollapsible);
|
el.querySelectorAll('.app-collapsible').forEach(AppCollapsible);
|
||||||
el.querySelectorAll('.app-icon').forEach(AppIcon);
|
el.querySelectorAll('.app-icon').forEach(AppIcon);
|
||||||
@@ -89,7 +89,7 @@ export function TodoApp(el) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Listen to the TodoStore's data.
|
// Listen to the TodoController's data.
|
||||||
// This is the main update.
|
// This is the main update.
|
||||||
// Everything else is related to drag & drop or FLIP animations.
|
// Everything else is related to drag & drop or FLIP animations.
|
||||||
el.addEventListener('todoData', (e) => {
|
el.addEventListener('todoData', (e) => {
|
||||||
@@ -104,7 +104,7 @@ export function TodoApp(el) {
|
|||||||
el.addEventListener('draggableCancel', flip);
|
el.addEventListener('draggableCancel', flip);
|
||||||
el.addEventListener('draggableDrop', flip);
|
el.addEventListener('draggableDrop', flip);
|
||||||
|
|
||||||
el.dispatchEvent(new CustomEvent('loadTodoStore'));
|
el.dispatchEvent(new CustomEvent('loadTodoData'));
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
el.querySelectorAll('.todo-frame').forEach((el) =>
|
el.querySelectorAll('.todo-frame').forEach((el) =>
|
||||||
|
@@ -3,11 +3,11 @@ import { TodoLogic } from './TodoLogic.js';
|
|||||||
/**
|
/**
|
||||||
* @param {HTMLElement} el
|
* @param {HTMLElement} el
|
||||||
*/
|
*/
|
||||||
export function TodoStore(el) {
|
export function TodoController(el) {
|
||||||
let todoData = TodoLogic.initTodoData();
|
let todoData = TodoLogic.initTodoData();
|
||||||
let saveTimeout;
|
let saveTimeout;
|
||||||
|
|
||||||
el.addEventListener('loadTodoStore', load);
|
el.addEventListener('loadTodoData', load);
|
||||||
|
|
||||||
for (const action of [
|
for (const action of [
|
||||||
'addTodoItem',
|
'addTodoItem',
|
Reference in New Issue
Block a user