Commit d5d4ec64 authored by Sindre Sorhus's avatar Sindre Sorhus

Merge pull request #710 from petehunt/tabify

Tabify React examples
parents 84c47397 5e455c5b
...@@ -61,9 +61,9 @@ ...@@ -61,9 +61,9 @@
toggleAll: function (event) { toggleAll: function (event) {
var checked = event.target.checked; var checked = event.target.checked;
// Note: it's usually better to use immutable data structures since they're easier to // Note: it's usually better to use immutable data structures since they're easier to
// reason about and React works very well with them. That's why we use map() and filter() // reason about and React works very well with them. That's why we use map() and filter()
// everywhere instead of mutating the array or todo items themselves. // everywhere instead of mutating the array or todo items themselves.
var newTodos = this.state.todos.map(function (todo) { var newTodos = this.state.todos.map(function (todo) {
return Utils.extend({}, todo, {completed: checked}); return Utils.extend({}, todo, {completed: checked});
}); });
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
toggle: function (todoToToggle) { toggle: function (todoToToggle) {
var newTodos = this.state.todos.map(function (todo) { var newTodos = this.state.todos.map(function (todo) {
return todo !== todoToToggle ? todo : Utils.extend({}, todo, {completed: !todo.completed}); return todo !== todoToToggle ? todo : Utils.extend({}, todo, {completed: !todo.completed});
}); });
this.setState({todos: newTodos}); this.setState({todos: newTodos});
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
save: function (todoToSave, text) { save: function (todoToSave, text) {
var newTodos = this.state.todos.map(function (todo) { var newTodos = this.state.todos.map(function (todo) {
return todo !== todoToSave ? todo : Utils.extend({}, todo, {title: text}); return todo !== todoToSave ? todo : Utils.extend({}, todo, {title: text});
}); });
this.setState({todos: newTodos, editing: null}); this.setState({todos: newTodos, editing: null});
...@@ -149,9 +149,9 @@ ...@@ -149,9 +149,9 @@
); );
}, this); }, this);
var activeTodoCount = this.state.todos.reduce(function(accum, todo) { var activeTodoCount = this.state.todos.reduce(function(accum, todo) {
return todo.completed ? accum : accum + 1; return todo.completed ? accum : accum + 1;
}, 0); }, 0);
var completedCount = this.state.todos.length - activeTodoCount; var completedCount = this.state.todos.length - activeTodoCount;
......
...@@ -54,12 +54,12 @@ ...@@ -54,12 +54,12 @@
return {editText: this.props.todo.title}; return {editText: this.props.todo.title};
}, },
/** /**
* This is a completely optional performance enhancement that you can implement * This is a completely optional performance enhancement that you can implement
* on any React component. If you were to delete this method the app would still * on any React component. If you were to delete this method the app would still
* work correctly (and still be very performant!), we just use it as an example * work correctly (and still be very performant!), we just use it as an example
* of how little code it takes to get an order of magnitude performance improvement. * of how little code it takes to get an order of magnitude performance improvement.
*/ */
shouldComponentUpdate: function (nextProps, nextState) { shouldComponentUpdate: function (nextProps, nextState) {
return ( return (
nextProps.todo.id !== this.props.todo.id || nextProps.todo.id !== this.props.todo.id ||
......
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