Update
This commit is contained in:
parent
e8026a4b11
commit
63235074c9
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,4 @@
|
|||
"use strict";
|
||||
var todoExists = Syndicate.Struct.makeConstructor("todoExists", ["id"]);
|
||||
var todo = Syndicate.Struct.makeConstructor("todo", ["id","title","completed"]);
|
||||
|
||||
var createTodo = Syndicate.Struct.makeConstructor("createTodo", ["title"]);
|
||||
|
@ -27,7 +26,6 @@ function todoListItemModel(initialId, initialTitle, initialCompleted) {
|
|||
this.completed = initialCompleted;
|
||||
|
||||
Syndicate.Actor.createFacet()
|
||||
.addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(todoExists(this.id), 0); }))
|
||||
.addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(todo(this.id,this.title,this.completed), 0); }))
|
||||
.onEvent(false, "message", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(setCompleted(this.id,_), 0); }), (function() { var _ = Syndicate.__; return { assertion: setCompleted(this.id,(Syndicate._$("v"))), metalevel: 0 }; }), (function(v) { this.completed = v; }))
|
||||
.onEvent(false, "message", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(setAllCompleted(_), 0); }), (function() { var _ = Syndicate.__; return { assertion: setAllCompleted((Syndicate._$("v"))), metalevel: 0 }; }), (function(v) { this.completed = v; }))
|
||||
|
@ -80,7 +78,7 @@ function todoListItemView(id) {
|
|||
Syndicate.Dataspace.send((newTitle ? setTitle(id, newTitle) : deleteTodo(id)));
|
||||
this.editing = false;
|
||||
}))
|
||||
.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todoExists(id), 0); }), (function() { var _ = Syndicate.__; return { assertion: todoExists(id), metalevel: 0 }; }), (function() {})).completeBuild();
|
||||
.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(id,_,_), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo(id,_,_), metalevel: 0 }; }), (function() {})).completeBuild();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -123,7 +121,7 @@ var G = new Syndicate.Ground(function () {
|
|||
.onEvent(false, "message", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(Syndicate.UI.globalEvent('.toggle-all','change',_), 0); }), (function() { var _ = Syndicate.__; return { assertion: Syndicate.UI.globalEvent('.toggle-all','change',(Syndicate._$("e"))), metalevel: 0 }; }), (function(e) {
|
||||
Syndicate.Dataspace.send(setAllCompleted(e.target.checked));
|
||||
}))
|
||||
.onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todoExists(_), 0); }), (function() { var _ = Syndicate.__; return { assertion: todoExists((Syndicate._$("id"))), metalevel: 0 }; }), (function(id) {
|
||||
.onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(_,_,_), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo((Syndicate._$("id")),_,_), metalevel: 0 }; }), (function(id) {
|
||||
todoListItemView(id);
|
||||
})).completeBuild();
|
||||
});
|
||||
|
@ -132,8 +130,8 @@ var G = new Syndicate.Ground(function () {
|
|||
var completedCount = 0;
|
||||
var activeCount = 0;
|
||||
Syndicate.Actor.createFacet()
|
||||
.onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(_,_,_), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo(_,_,(Syndicate._$("completed"))), metalevel: 0 }; }), (function(completed) { if (completed) completedCount++; else activeCount++; }))
|
||||
.onEvent(false, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(_,_,_), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo(_,_,(Syndicate._$("completed"))), metalevel: 0 }; }), (function(completed) { if (completed) completedCount--; else activeCount--; }))
|
||||
.onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(_,_,_), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo((Syndicate._$("id")),_,(Syndicate._$("completed"))), metalevel: 0 }; }), (function(id, completed) { if (completed) completedCount++; else activeCount++; }))
|
||||
.onEvent(false, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(_,_,_), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo((Syndicate._$("id")),_,(Syndicate._$("completed"))), metalevel: 0 }; }), (function(id, completed) { if (completed) completedCount--; else activeCount--; }))
|
||||
.addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(activeTodoCount(activeCount), 0); }))
|
||||
.addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(completedTodoCount(completedCount), 0); }))
|
||||
.addAssertion((function() { var _ = Syndicate.__; return Syndicate.Patch.assert(totalTodoCount(activeCount+completedCount), 0); }))
|
||||
|
@ -180,15 +178,17 @@ var G = new Syndicate.Ground(function () {
|
|||
.onEvent(false, "message", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(createTodo(_), 0); }), (function() { var _ = Syndicate.__; return { assertion: createTodo((Syndicate._$("title"))), metalevel: 0 }; }), (function(title) {
|
||||
todoListItemModel(db.nextId++, title, false);
|
||||
}))
|
||||
.onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(_,_,_), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo((Syndicate._$("id")),(Syndicate._$("title")),(Syndicate._$("completed"))), metalevel: 0 }; }), (function(id, title, completed) { Syndicate.Actor.createFacet()
|
||||
.onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(_,_,_), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo((Syndicate._$("id")),_,_), metalevel: 0 }; }), (function(id) { Syndicate.Actor.createFacet()
|
||||
.onEvent(false, "asserted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(id,_,_), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo(id,(Syndicate._$("title")),(Syndicate._$("completed"))), metalevel: 0 }; }), (function(title, completed) { Syndicate.Actor.createFacet()
|
||||
.addInitBlock((function() {
|
||||
db.todos[id] = {id: id, title: title, completed: completed};
|
||||
localStorage['todos-syndicate'] = JSON.stringify(db);
|
||||
}))
|
||||
db.todos[id] = {id: id, title: title, completed: completed};
|
||||
localStorage['todos-syndicate'] = JSON.stringify(db);
|
||||
}))
|
||||
.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(id,title,completed), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo(id,title,completed), metalevel: 0 }; }), (function() {})).completeBuild(); }))
|
||||
.addDoneBlock((function() {
|
||||
delete db.todos[id];
|
||||
localStorage['todos-syndicate'] = JSON.stringify(db);
|
||||
}))
|
||||
.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(id,title,completed), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo(id,title,completed), metalevel: 0 }; }), (function() {})).completeBuild(); })).completeBuild();
|
||||
.onEvent(true, "retracted", (function() { var _ = Syndicate.__; return Syndicate.Patch.sub(todo(id,_,_), 0); }), (function() { var _ = Syndicate.__; return { assertion: todo(id,_,_), metalevel: 0 }; }), (function() {})).completeBuild(); })).completeBuild();
|
||||
});
|
||||
}).startStepping();
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
- BUG: transitions don't happen because the nodes are being replaced rather than edited.
|
||||
*/
|
||||
|
||||
assertion type todoExists(id);
|
||||
assertion type todo(id, title, completed);
|
||||
|
||||
message type createTodo(title);
|
||||
|
@ -31,7 +30,6 @@ function todoListItemModel(initialId, initialTitle, initialCompleted) {
|
|||
this.completed = initialCompleted;
|
||||
|
||||
react {
|
||||
assert todoExists(this.id);
|
||||
assert todo(this.id, this.title, this.completed);
|
||||
|
||||
on message setCompleted(this.id, $v) { this.completed = v; }
|
||||
|
@ -104,7 +102,7 @@ function todoListItemView(id) {
|
|||
this.editing = false;
|
||||
}
|
||||
} until {
|
||||
case retracted todoExists(id);
|
||||
case retracted todo(id, _, _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +151,7 @@ ground dataspace G {
|
|||
:: setAllCompleted(e.target.checked);
|
||||
}
|
||||
|
||||
on asserted todoExists($id) {
|
||||
on asserted todo($id, _, _) {
|
||||
todoListItemView(id);
|
||||
}
|
||||
}
|
||||
|
@ -163,8 +161,8 @@ ground dataspace G {
|
|||
var completedCount = 0;
|
||||
var activeCount = 0;
|
||||
react {
|
||||
on asserted todo(_, _, $completed) { if (completed) completedCount++; else activeCount++; }
|
||||
on retracted todo(_, _, $completed) { if (completed) completedCount--; else activeCount--; }
|
||||
on asserted todo($id, _, $completed) { if (completed) completedCount++; else activeCount++; }
|
||||
on retracted todo($id, _, $completed) { if (completed) completedCount--; else activeCount--; }
|
||||
assert activeTodoCount(activeCount);
|
||||
assert completedTodoCount(completedCount);
|
||||
assert totalTodoCount(activeCount + completedCount);
|
||||
|
@ -217,10 +215,12 @@ ground dataspace G {
|
|||
todoListItemModel(db.nextId++, title, false);
|
||||
}
|
||||
|
||||
during todo($id, $title, $completed) {
|
||||
do {
|
||||
db.todos[id] = {id: id, title: title, completed: completed};
|
||||
localStorage['todos-syndicate'] = JSON.stringify(db);
|
||||
during todo($id, _, _) {
|
||||
during todo(id, $title, $completed) {
|
||||
do {
|
||||
db.todos[id] = {id: id, title: title, completed: completed};
|
||||
localStorage['todos-syndicate'] = JSON.stringify(db);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
delete db.todos[id];
|
||||
|
|
Loading…
Reference in New Issue