-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
58 lines (48 loc) · 1.74 KB
/
app.js
File metadata and controls
58 lines (48 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import router from "./core/router.js";
import todoState from "./core/state.js";
import TodoApp from "./components/templates/app-todo.js";
import Footer from "./components/templates/footer.js";
import todoMain from "./components/organisms/todo-main.js";
import todoFooter from "./components/organisms/todo-footer.js";
import todoList from "./components/molecules/todo-list.js";
import clearCompleted from "./components/atoms/clear-completed.js";
import todoCount from "./components/atoms/todo-count.js";
//----------------------------------------------------------------
// Set the state management of the application
todoState.set({
todos: [],
filter: "all",
counter: {
active: 0,
completed: 0,
}
});
// Subscribe initial callbacks.
todoState.subscribe(todoMain.display.bind(todoMain));
todoState.subscribe(todoFooter.display.bind(todoFooter));
todoState.subscribe(todoList.display.bind(todoList));
todoState.subscribe(clearCompleted.display.bind(clearCompleted));
todoState.subscribe(todoCount.refresh.bind(todoCount));
//----------------------------------------------------------------
// Set the routes of the application with
// their respective associated handlers.
// The handlers set the filter property
// of the state object. The state will then
// notify the subscribed handlers to render the
// corresponding components.
router.add("/", () => {
todoState.set({ filter: "all" });
})
router.add("/active", () => {
todoState.set({ filter: "active" });
});
router.add("/completed", () => {
todoState.set({ filter: "completed" });
});
//----------------------------------------------------------------
// Render the initial Page with all components.
document.body.append(
TodoApp.render(),
Footer.render(),
);
export default todoState