Doesn’t work. Launches but it doesn’t show anything and when I click it crashes saying ‘Cannot read property ‘value’ of undefined.’ What am i doing wrong
var Observable = require("FuseJS/Observable");
var Storage = require("FuseJS/Storage");
function Task(title){
var self = this;
this.title = title;
this.checked = Observable(false);
this.hidden = Observable(function(){
if (currentTab.value == "all"){
return false;
}
else if (currentTab.value == "active"){
return self.checked.value ? true : false;
}
else {
return self.checked.value ? false : true;
}
});
}
function Push() {
var string = "module.exports = " + JSON.stringify(todoList);
Storage.write("todoListJSON", string);
}
var json = '{"_subscribers":[null],"_isLeaf":true,"_values":[{"title":"Test","checked":{"_subscribers":[null],"_isLeaf":true,"_values":[true]},"hidden":{"_subscribers":[null],"_values":[false],"_dependencies":[{"_subscribers":[null,null,null],"_isLeaf":true,"_values":["all"]}]}},{"title":"Test1","checked":{"_subscribers":[null],"_isLeaf":true,"_values":[false]},"hidden":{"_subscribers":[null],"_values":[false],"_dependencies":[{"_subscribers":[null,null,null],"_isLeaf":true,"_values":["all"]}]}},{"title":"Test2","checked":{"_subscribers":[null],"_isLeaf":true,"_values":[true]},"hidden":{"_subscribers":[null],"_values":[false],"_dependencies":[{"_subscribers":[null,null,null],"_isLeaf":true,"_values":["all"]}]}}]}';
var todoList = Observable();
var titleInput = Observable("");
var currentTab = Observable("all");
todoList.value = JSON.parse(json);
var remainingCount = todoList.count(function(x){
return x.checked.not();
});
var remainingText = remainingCount.map(function(x){
return x + " " + ((x == 1) ? "task" : "tasks") + " remaining";
});
var canClearCompleted = todoList.count(function(x){
return x.checked;
}).map(function(x){
return x > 0;
});
function addItem(arg) {
todoList.add(new Task(titleInput.value));
Push();
}
function deleteItem(arg){
todoList.tryRemove(arg.data);
Push();
}
function toggleAll(arg) {
var remaining = remainingCount.value;
todoList.forEach(function(x){
x.checked.value = !x.checked.value;
});
Push();
}
function toggleItem(arg) {
arg.data.checked.value = !arg.data.checked.value;
Push();
}
function clearCompleted() {
todoList.removeWhere(function(x) { return x.checked.value; });
Push();
}
function showAll() {
currentTab.value = "all";
}
function showActive() {
currentTab.value = "active";
}
function showCompleted() {
currentTab.value = "completed";
}
module.exports = {
todoList: todoList,
titleInput: titleInput,
currentTab: currentTab,
remainingText: remainingText,
canClearCompleted: canClearCompleted,
addItem: addItem,
deleteItem: deleteItem,
toggleAll: toggleAll,
toggleItem: toggleItem,
clearCompleted: clearCompleted,
showAll: showAll,
showActive: showActive,
showCompleted: showCompleted
};