react-templates/playground/samples/todo.code

24 lines
838 B
Plaintext
Raw Normal View History

2014-12-02 17:59:03 +01:00
{
mixins: [React.addons.LinkedStateMixin],
getInitialState: function () {
return {edited: '', todos: [], counter: 0};
2014-12-02 17:59:03 +01:00
},
add: function () {
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})});
}
}