Commit 90fef1df authored by oscarballadares's avatar oscarballadares

Remove React onEdit workaround

parent c0762487
...@@ -62,12 +62,8 @@ var app = app || {}; ...@@ -62,12 +62,8 @@ var app = app || {};
this.props.model.destroy(todo); this.props.model.destroy(todo);
}, },
edit: function (todo, callback) { edit: function (todo) {
// refer to todoItem.js `handleEdit` for the reasoning behind the this.setState({editing: todo.id});
// callback
this.setState({editing: todo.id}, function () {
callback();
});
}, },
save: function (todoToSave, text) { save: function (todoToSave, text) {
......
...@@ -23,15 +23,7 @@ var app = app || {}; ...@@ -23,15 +23,7 @@ var app = app || {};
}, },
handleEdit: function () { handleEdit: function () {
// react optimizes renders by batching them. This means you can't call this.props.onEdit();
// parent's `onEdit` (which in this case triggeres a re-render), and
// immediately manipulate the DOM as if the rendering's over. Put it as a
// callback. Refer to app.jsx' `edit` method
this.props.onEdit(function () {
var node = this.refs.editField.getDOMNode();
node.focus();
node.setSelectionRange(node.value.length, node.value.length);
}.bind(this));
this.setState({editText: this.props.todo.title}); this.setState({editText: this.props.todo.title});
}, },
...@@ -67,6 +59,20 @@ var app = app || {}; ...@@ -67,6 +59,20 @@ var app = app || {};
); );
}, },
/**
* Safely manipulate the DOM after updating the state when invoking
* `this.props.onEdit()` in the `handleEdit` method above.
* For more info refer to notes at https://facebook.github.io/react/docs/component-api.html#setstate
* and https://facebook.github.io/react/docs/component-specs.html#updating-componentdidupdate
*/
componentDidUpdate: function (prevProps) {
if (!prevProps.editing && this.props.editing) {
var node = this.refs.editField.getDOMNode();
node.focus();
node.setSelectionRange(node.value.length, node.value.length);
}
},
render: function () { render: function () {
return ( return (
<li className={React.addons.classSet({ <li className={React.addons.classSet({
......
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