Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Commit d1617f5

Browse files
committed
eager loading optimization
1 parent dfc9e3c commit d1617f5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

public/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
setInterval(this.loadCommentsFromServer, this.props.pollInterval);
4747
},
4848
handleCommentSubmit: function(comment) {
49+
var comments = this.state.data;
50+
// Optimistically set an id on the new comment. It will be replaced by an
51+
// id generated by the server. In a production application you would likely
52+
// not use Date.now() for this and would have a more robust system in place.
53+
comment.id = Date.now();
54+
var newComments = comments.concat([comment]);
55+
this.setState({data: newComments});
4956
$.ajax({
5057
url: this.props.url,
5158
dataType: 'json',
@@ -55,6 +62,7 @@
5562
this.setState({data: data});
5663
}.bind(this),
5764
error: function(xhr, status, err) {
65+
this.setState({data: comments});
5866
console.error(this.props.url, status, err.toString());
5967
}.bind(this)
6068
});

0 commit comments

Comments
 (0)