Browse Source

Merge pull request #1386 from georgesisco/master

In the tutorial, carry ajax error checking from step 13 forward to other ajax steps
main
Paul O’Shannessy 11 years ago
parent
commit
e203b54fb7
  1. 26
      docs/tutorial.md

26
docs/tutorial.md

@ -411,7 +411,7 @@ var CommentBox = React.createClass({
Here, `componentWillMount` is a method called automatically by React before a component is rendered. The key to dynamic updates is the call to `this.setState()`. We replace the old array of comments with the new one from the server and the UI automatically updates itself. Because of this reactivity, it is only a minor change to add live updates. We will use simple polling here but you could easily use WebSockets or other technologies.
```javascript{3,16-17,31}
```javascript{3,19-20,34}
// tutorial14.js
var CommentBox = React.createClass({
loadCommentsFromServer: function() {
@ -420,6 +420,9 @@ var CommentBox = React.createClass({
dataType: 'json',
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
@ -517,7 +520,7 @@ When a user submits a comment, we will need to refresh the list of comments to i
We need to pass data from the child component to its parent. We do this by passing a `callback` in props from parent to child:
```javascript{12-14,28}
```javascript{15-17,31}
// tutorial17.js
var CommentBox = React.createClass({
loadCommentsFromServer: function() {
@ -526,6 +529,9 @@ var CommentBox = React.createClass({
dataType: 'json',
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
@ -584,7 +590,7 @@ var CommentForm = React.createClass({
Now that the callbacks are in place, all we have to do is submit to the server and refresh the list:
```javascript{13-21}
```javascript{16-27}
// tutorial19.js
var CommentBox = React.createClass({
loadCommentsFromServer: function() {
@ -593,6 +599,9 @@ var CommentBox = React.createClass({
dataType: 'json',
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
@ -604,6 +613,9 @@ var CommentBox = React.createClass({
data: comment,
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
@ -632,7 +644,7 @@ var CommentBox = React.createClass({
Our application is now feature complete but it feels slow to have to wait for the request to complete before your comment appears in the list. We can optimistically add this comment to the list to make the app feel faster.
```javascript{13-15}
```javascript{16-18}
// tutorial20.js
var CommentBox = React.createClass({
loadCommentsFromServer: function() {
@ -641,6 +653,9 @@ var CommentBox = React.createClass({
dataType: 'json',
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},
@ -655,6 +670,9 @@ var CommentBox = React.createClass({
data: comment,
success: function(data) {
this.setState({data: data});
}.bind(this),
error: function(xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this)
});
},

Loading…
Cancel
Save