Commit 9555657d authored by Colin Eberhardt's avatar Colin Eberhardt Committed by Sam Saccone

code-style - simple fomatting changes

parent 60c78081
......@@ -19,7 +19,9 @@ var TodoApp = (function () {
todo.setTitle(editedTitle.value);
todo.editing = false;
};
TodoApp.prototype.cancelEditingTodo = function (todo) { todo.editing = false; };
TodoApp.prototype.cancelEditingTodo = function (todo) {
todo.editing = false;
};
TodoApp.prototype.updateEditingTodo = function (editedTitle, todo) {
editedTitle = editedTitle.value.trim();
todo.editing = false;
......
......@@ -10,14 +10,20 @@ const ENTER_KEY = 13;
})
export default class TodoApp {
todoStore: TodoStore;
constructor() {
this.todoStore = new TodoStore();
}
stopEditing(todo: Todo, editedTitle) {
todo.setTitle(editedTitle.value);
todo.editing = false;
}
cancelEditingTodo(todo: Todo) { todo.editing = false; }
cancelEditingTodo(todo: Todo) {
todo.editing = false;
}
updateEditingTodo(editedTitle, todo: Todo) {
editedTitle = editedTitle.value.trim();
todo.editing = false;
......@@ -28,18 +34,23 @@ export default class TodoApp {
todo.setTitle(editedTitle);
}
editTodo(todo: Todo) {
todo.editing = true;
}
removeCompleted() {
this.todoStore.removeCompleted();
}
toggleCompletion(todo: Todo) {
this.todoStore.toggleCompletion(todo);
}
remove(todo: Todo){
this.todoStore.remove(todo);
}
addTodo($event, newtodo) {
if ($event.which === ENTER_KEY && newtodo.value.trim().length) {
this.todoStore.add(newtodo.value);
......
......@@ -2,9 +2,11 @@ export class Todo {
completed: Boolean;
editing: Boolean;
title: String;
setTitle(title: String) {
this.title = title.trim();
}
constructor(title: String) {
this.completed = false;
this.editing = false;
......@@ -14,6 +16,7 @@ export class Todo {
export class TodoStore {
todos: Array<Todo>;
constructor() {
let persistedTodos = JSON.parse(localStorage.getItem('angular2-todos') || '[]');
// Normalize back into classes
......@@ -23,36 +26,46 @@ export class TodoStore {
return ret;
});
}
_updateStore() {
localStorage.setItem('angular2-todos', JSON.stringify(this.todos));
}
get(state: {completed: Boolean}) {
return this.todos.filter((todo: Todo) => todo.completed === state.completed);
}
allCompleted() {
return this.todos.length === this.getCompleted().length;
}
setAllTo(toggler) {
this.todos.forEach((t: Todo) => t.completed = toggler.checked);
this._updateStore();
}
removeCompleted() {
this.todos = this.get({completed: false});
}
getRemaining() {
return this.get({completed: false});
}
getCompleted() {
return this.get({completed: true});
}
toggleCompletion(todo: Todo) {
todo.completed = !todo.completed;
this._updateStore();
}
remove(todo: Todo) {
this.todos.splice(this.todos.indexOf(todo), 1);
this._updateStore();
}
add(title: String) {
this.todos.push(new Todo(title));
this._updateStore();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment