Skip to content

Commit b5038c7

Browse files
committed
feat(app): implement toggle state
1 parent f0b1efd commit b5038c7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/todo-item-model.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,11 @@ class TodoItem extends Model {
88
completed: false
99
};
1010
}
11+
12+
toggle() {
13+
this.save({
14+
completed: !this.get('completed')
15+
});
16+
}
1117
}
1218
export default TodoItem;

src/todo-item-view.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class TodoItemView extends View {
77
this.tagName = 'li';
88
// *Cache the template function for a single item.*
99
this.template = _.template(`
10-
<input type="checkbox">
10+
<input type="checkbox" class="<%= completed ? 'is-complete' : '' %>" <%= completed ? 'checked' : '' %>>
1111
<span class="todoText"><%- title %></span>
1212
<i class="removeBtn fa fa-times"></i>
1313
`);
@@ -19,7 +19,7 @@ class TodoItemView extends View {
1919
};
2020
super(options);
2121

22-
22+
this.listenTo(this.model, 'change', this.render);
2323
this.listenTo(this.model, 'destroy', this.remove);
2424
}
2525

0 commit comments

Comments
 (0)