|
@@ -43,16 +43,19 @@ let CommentForm = React.createClass({
|
|
});
|
|
});
|
|
|
|
|
|
let CommentBox = React.createClass({
|
|
let CommentBox = React.createClass({
|
|
|
|
+ componentDidMount: function () {
|
|
|
|
+ this.loadCommentsFromServer();
|
|
|
|
+ setInterval(this.loadCommentsFromServer, this.props.pollInterval);
|
|
|
|
+ },
|
|
getInitialState: function () {
|
|
getInitialState: function () {
|
|
return { data: [] };
|
|
return { data: [] };
|
|
},
|
|
},
|
|
- componentDidMount: function () {
|
|
|
|
|
|
+ loadCommentsFromServer: function () {
|
|
$.ajax({
|
|
$.ajax({
|
|
url: this.props.url,
|
|
url: this.props.url,
|
|
dataType: "json",
|
|
dataType: "json",
|
|
cache: false,
|
|
cache: false,
|
|
success: function (result) {
|
|
success: function (result) {
|
|
- console.log('Received frop api: ', result);
|
|
|
|
this.setState({ data: result });
|
|
this.setState({ data: result });
|
|
}.bind(this),
|
|
}.bind(this),
|
|
error: function (xhr, status, err) {
|
|
error: function (xhr, status, err) {
|
|
@@ -72,6 +75,6 @@ let CommentBox = React.createClass({
|
|
});
|
|
});
|
|
|
|
|
|
ReactDOM.render(
|
|
ReactDOM.render(
|
|
- <CommentBox url="/api/comments" />,
|
|
|
|
|
|
+ <CommentBox url="/api/comments" pollInterval={2000} />,
|
|
document.getElementById("content")
|
|
document.getElementById("content")
|
|
);
|
|
);
|