-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtodolist.js
37 lines (31 loc) · 1.01 KB
/
todolist.js
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
'use strict';
var observable = require('poochie/observable');
var gizmos = require('./gizmos');
var tododata = require('./tododata');
var todoitem = require('./todoitem');
function todoList(oTodoData, oFragment) {
function todoItem(itemData, index) {
var handlers = {
remove: function() { tododata.removeItem(index, oTodoData); }
};
return todoitem.todoItem({
text: itemData.text,
completed: itemData.completed,
handlers: handlers
});
}
function todoItems(todoData, fragment) {
if (fragment === '/active') {
todoData = todoData.filter(function(x){ return !x.completed.get(); });
} else if (fragment === '/completed') {
todoData = todoData.filter(function(x){ return x.completed.get(); });
}
return todoData.map(todoItem);
}
var oIsCompletedFields = tododata.getIsCompletedFields(oTodoData);
var oItems = observable.subscriber([oTodoData, oFragment, oIsCompletedFields], todoItems);
return gizmos.container(oItems, 'ul', 'todo-list');
}
module.exports = {
todoList: todoList
};