diff --git a/todomvc/common/actions.js b/todomvc/common/actions.js
index a4d7d595..fec82c65 100644
--- a/todomvc/common/actions.js
+++ b/todomvc/common/actions.js
@@ -2,8 +2,14 @@
(function(ref) {
ref.actions = function(sendUpdate) {
return {
- saveTodo: function(todo) {
- sendUpdate({ saveTodo: { title: todo } });
+ saveTodo: function(todo, id) {
+ sendUpdate({ saveTodo: { title: todo, id: id } });
+ },
+ editTodo: function(todoId) {
+ sendUpdate({ editTodoId: todoId, editing: true });
+ },
+ cancelEdit: function(todoId) {
+ sendUpdate({ editTodoId: todoId, editing: false });
},
deleteTodoId: function(todoId) {
sendUpdate({ deleteTodoId: todoId });
diff --git a/todomvc/common/store.js b/todomvc/common/store.js
index 449661ec..70df6a87 100644
--- a/todomvc/common/store.js
+++ b/todomvc/common/store.js
@@ -1,6 +1,5 @@
(function(ref) {
var STORAGE_KEY = "meiosis-todomvc";
- var nextId = 1;
var findIndex = function(todos, todoId) {
var index = -1;
@@ -34,7 +33,7 @@
todos = replaceTodoAtIndex(todos, todo, findIndex(todos, todo.id));
}
else {
- todo.id = nextId++;
+ todo.id = new Date().getTime();
todos = todos.concat([todo]);
}
localStorage.setItem(STORAGE_KEY, JSON.stringify(todos));
diff --git a/todomvc/common/viewModel.js b/todomvc/common/viewModel.js
new file mode 100644
index 00000000..b482bb94
--- /dev/null
+++ b/todomvc/common/viewModel.js
@@ -0,0 +1,20 @@
+/*global window*/
+(function(ref) {
+ ref.viewModel = function(createComponent) {
+ createComponent({
+ receiveUpdate: function(model, update) {
+ if (update.editTodoId) {
+ for (var i = 0, t = model.todos.length; i < t; i++) {
+ var todo = model.todos[i];
+
+ if (todo.id === update.editTodoId) {
+ todo.editing = update.editing;
+ break;
+ }
+ }
+ }
+ return model;
+ }
+ });
+ };
+})(window);
diff --git a/todomvc/index.html b/todomvc/index.html
index fa36ccb2..29442fdc 100644
--- a/todomvc/index.html
+++ b/todomvc/index.html
@@ -16,7 +16,9 @@
+
+