Skip to content

Commit

Permalink
Working on TodoMVC examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
foxdonut committed May 6, 2016
1 parent 5e91d4d commit e28fe5d
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 13 deletions.
10 changes: 8 additions & 2 deletions todomvc/common/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
3 changes: 1 addition & 2 deletions todomvc/common/store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(function(ref) {
var STORAGE_KEY = "meiosis-todomvc";
var nextId = 1;

var findIndex = function(todos, todoId) {
var index = -1;
Expand Down Expand Up @@ -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));
Expand Down
20 changes: 20 additions & 0 deletions todomvc/common/viewModel.js
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 2 additions & 0 deletions todomvc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<script src="common/model.js"></script>
<script src="common/nextUpdate.js"></script>
<script src="common/receiveUpdate.js"></script>
<script src="common/viewModel.js"></script>
<script src="vanillajs/view.js"></script>
<script src="vanillajs/ready.js"></script>
<script src="vanillajs/postRender.js"></script>
<script src="vanillajs/main.js"></script>
</html>
1 change: 1 addition & 0 deletions todomvc/js/meiosis-vanillajs.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion todomvc/js/meiosis.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e28fe5d

Please sign in to comment.