Commit 2206d218 authored by Arthur Verschaeve's avatar Arthur Verschaeve

typescript-backbone: use correct variable names

Ref #359
Close #1237
parent c0762487
...@@ -77,13 +77,13 @@ https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html ...@@ -77,13 +77,13 @@ https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html
<!-- Templates --> <!-- Templates -->
<script type="text/template" id="item-template"> <script type="text/template" id="item-template">
<div class="todo <%= done ? 'done' : '' %>"> <div class="todo <%= completed ? 'done' : '' %>">
<div class="view display"> <div class="view display">
<input class="toggle check" type="checkbox" <%= done ? 'checked' : '' %>> <input class="toggle check" type="checkbox" <%= completed ? 'checked' : '' %>>
<label class="todo-content"><%= content %></label> <label class="todo-content"><%= title %></label>
<button class="destroy"></button> <button class="destroy"></button>
</div> </div>
<input class="edit todo-input" value="<%= content %>"> <input class="edit todo-input" value="<%= title %>">
</div> </div>
</script> </script>
...@@ -94,9 +94,9 @@ https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html ...@@ -94,9 +94,9 @@ https://github.com/documentcloud/backbone/blob/master/examples/todos/index.html
<span class="word"><%= remaining == 1 ? 'item' : 'items' %></span> left <span class="word"><%= remaining == 1 ? 'item' : 'items' %></span> left
</span> </span>
<% } %> <% } %>
<% if (done) { %> <% if (completed) { %>
<span class="todo-clear"> <span class="todo-clear">
<button id="clear-completed">Clear completed (<span class="number-done"><%= done %></span>)</button> <button id="clear-completed">Clear completed (<span class="number-done"><%= completed %></span>)</button>
</span> </span>
<% } %> <% } %>
</script> </script>
......
This diff is collapsed.
...@@ -93,27 +93,27 @@ declare var Store: any; ...@@ -93,27 +93,27 @@ declare var Store: any;
// Todo Model // Todo Model
// ---------- // ----------
// Our basic **Todo** model has `content`, `order`, and `done` attributes. // Our basic **Todo** model has `title`, `order`, and `completed` attributes.
class Todo extends Backbone.Model { class Todo extends Backbone.Model {
// Default attributes for the todo. // Default attributes for the todo.
defaults() { defaults() {
return { return {
content: '', title: '',
done: false completed: false
} }
} }
// Ensure that each todo created has `content`. // Ensure that each todo created has `title`.
initialize() { initialize() {
if (!this.get('content')) { if (!this.get('title')) {
this.set({ 'content': this.defaults().content }); this.set({ 'title': this.defaults().title });
} }
} }
// Toggle the `done` state of this todo item. // Toggle the `completed` state of this todo item.
toggle() { toggle() {
this.save({ done: !this.get('done') }); this.save({ completed: !this.get('completed') });
} }
// Remove this Todo from *localStorage* and delete its view. // Remove this Todo from *localStorage* and delete its view.
...@@ -136,14 +136,14 @@ class TodoList extends Backbone.Collection { ...@@ -136,14 +136,14 @@ class TodoList extends Backbone.Collection {
// Save all of the todo items under the `'todos'` namespace. // Save all of the todo items under the `'todos'` namespace.
localStorage = new Store('todos-typescript-backbone'); localStorage = new Store('todos-typescript-backbone');
// Filter down the list of all todo items that are finished. // Filter down the list of all todo items that are completed.
done() { completed() {
return this.filter((todo: Todo) => todo.get('done')); return this.filter((todo: Todo) => todo.get('completed'));
} }
// Filter down the list to only todo items that are still not finished. // Filter down the list to only todo items that are still not completed.
remaining() { remaining() {
return this.without.apply(this, this.done()); return this.without.apply(this, this.completed());
} }
// We keep the Todos in sequential order, despite being saved by unordered // We keep the Todos in sequential order, despite being saved by unordered
...@@ -212,7 +212,7 @@ class TodoView extends Backbone.View { ...@@ -212,7 +212,7 @@ class TodoView extends Backbone.View {
return this; return this;
} }
// Toggle the `'done'` state of the model. // Toggle the `completed` state of the model.
toggleDone() { toggleDone() {
this.model.toggle(); this.model.toggle();
} }
...@@ -228,7 +228,7 @@ class TodoView extends Backbone.View { ...@@ -228,7 +228,7 @@ class TodoView extends Backbone.View {
var trimmedValue = this.input.val().trim(); var trimmedValue = this.input.val().trim();
if (trimmedValue) { if (trimmedValue) {
this.model.save({ content: trimmedValue }); this.model.save({ title: trimmedValue });
} else { } else {
this.clear(); this.clear();
} }
...@@ -247,7 +247,7 @@ class TodoView extends Backbone.View { ...@@ -247,7 +247,7 @@ class TodoView extends Backbone.View {
if (e.which === TodoView.ESC_KEY) { if (e.which === TodoView.ESC_KEY) {
this.$el.removeClass('editing'); this.$el.removeClass('editing');
// Also reset the hidden input back to the original value. // Also reset the hidden input back to the original value.
this.input.val(this.model.get('content')); this.input.val(this.model.get('title'));
} }
} }
...@@ -304,7 +304,7 @@ class AppView extends Backbone.View { ...@@ -304,7 +304,7 @@ class AppView extends Backbone.View {
// Re-rendering the App just means refreshing the statistics -- the rest // Re-rendering the App just means refreshing the statistics -- the rest
// of the app doesn't change. // of the app doesn't change.
render() { render() {
var done = Todos.done().length; var completed = Todos.completed().length;
var remaining = Todos.remaining().length; var remaining = Todos.remaining().length;
if (Todos.length) { if (Todos.length) {
...@@ -313,7 +313,7 @@ class AppView extends Backbone.View { ...@@ -313,7 +313,7 @@ class AppView extends Backbone.View {
this.$('#todo-stats').html(this.statsTemplate({ this.$('#todo-stats').html(this.statsTemplate({
total: Todos.length, total: Todos.length,
done: done, completed: completed,
remaining: remaining remaining: remaining
})); }));
} else { } else {
...@@ -339,9 +339,9 @@ class AppView extends Backbone.View { ...@@ -339,9 +339,9 @@ class AppView extends Backbone.View {
// Generate the attributes for a new Todo item. // Generate the attributes for a new Todo item.
newAttributes() { newAttributes() {
return { return {
content: this.input.val().trim(), title: this.input.val().trim(),
order: Todos.nextOrder(), order: Todos.nextOrder(),
done: false completed: false
}; };
} }
...@@ -354,15 +354,15 @@ class AppView extends Backbone.View { ...@@ -354,15 +354,15 @@ class AppView extends Backbone.View {
} }
} }
// Clear all done todo items, destroying their models. // Clear all completed todo items, destroying their models.
clearCompleted() { clearCompleted() {
_.each(Todos.done(), (todo: Todo) => todo.clear()); _.each(Todos.completed(), (todo: Todo) => todo.clear());
return false; return false;
} }
toggleAllComplete() { toggleAllComplete() {
var done = this.allCheckbox.checked; var completed = this.allCheckbox.checked;
Todos.each((todo: Todo) => todo.save({ 'done': done })); Todos.each((todo: Todo) => todo.save({ 'completed': completed }));
} }
} }
......
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