2014-12-02 17:59:03 +01:00
|
|
|
{
|
|
|
|
mixins: [React.addons.LinkedStateMixin],
|
2014-12-07 14:12:50 +01:00
|
|
|
getInitialState: function () {
|
|
|
|
return {edited: '', todos: [], counter: 0};
|
2014-12-02 17:59:03 +01:00
|
|
|
},
|
|
|
|
add: function () {
|
2014-12-07 14:12:50 +01:00
|
|
|
if (this.state.edited.trim().length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-02 17:59:03 +01:00
|
|
|
var newTodo = {value: this.state.edited, done: false, key: this.state.counter};
|
|
|
|
this.setState({todos: this.state.todos.concat(newTodo), edited: '', counter: this.state.counter + 1});
|
|
|
|
},
|
|
|
|
remove: function (todo) {
|
|
|
|
this.setState({todos: _.reject(this.state.todos, todo)});
|
|
|
|
},
|
|
|
|
toggleChecked: function (index) {
|
|
|
|
var todos = _.cloneDeep(this.state.todos);
|
|
|
|
todos[index].done = !todos[index].done;
|
|
|
|
this.setState({todos: todos});
|
|
|
|
},
|
|
|
|
clearDone: function () {
|
|
|
|
this.setState({todos: _.filter(this.state.todos, {done: false})});
|
|
|
|
}
|
|
|
|
}
|