Skip to content

Commit 8fd1d50

Browse files
committed
Converted to use ES6 promise syntax
1 parent c46b03a commit 8fd1d50

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

webpack/assets/javascripts/CommentBox.jsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@ var Comment = React.createClass({
3232
});
3333

3434
var CommentBox = React.createClass({
35+
logError: function(xhr, status, err) {
36+
console.error(`Error loading comments from server!\nURL is ${this.props.url}\nstatus is ${status}\nerr is ${err.toString()}`);
37+
},
3538
loadCommentsFromServer: function() {
3639
$.ajax({
3740
url: this.props.url,
38-
dataType: 'json',
39-
success: data => {
41+
dataType: 'json'}).then(data => {
4042
this.setState({data: data});
41-
},
42-
error: (xhr, status, err) => {
43-
console.error(this.props.url, status, err.toString());
44-
}
45-
});
43+
}, this.logError);
4644
},
4745
emptyFormData: { author: "", text: "" },
4846
handleCommentSubmit: function() {
@@ -55,17 +53,14 @@ var CommentBox = React.createClass({
5553
url: this.props.url,
5654
dataType: 'json',
5755
type: 'POST',
58-
data: { comment: comment},
59-
success: data => {
56+
data: { comment: comment}}).then(data => {
6057
var comments = this.state.data;
6158
var newComments = React.addons.update(comments, { $push: [comment] } );
6259
this.setState({ajaxSending: false, data: newComments, formData: this.emptyFormData });
63-
},
64-
error: (xhr, status, err) => {
65-
console.error(this.props.url, status, err.toString());
60+
}, (xhr, status, err) => {
61+
this.logError(xhr, status, err);
6662
this.setState({ajaxSending: false});
67-
}
68-
});
63+
});
6964
},
7065
getInitialState: function() {
7166
return {

0 commit comments

Comments
 (0)