// IMPORTANT: Replace below with your Firebase app URL
var firebaseUrl = "https://my-firebase-app.firebaseio.com/";
var converter = new Showdown.converter();
var Comment = React.createClass({
render: function() {
var rawMarkup = converter.makeHtml(this.props.children.toString());
return (
{this.props.author}
);
}
});
var CommentList = React.createClass({
render: function() {
var commentNodes = this.props.data.map(function (comment, index) {
return {comment.text};
});
return {commentNodes}
;
}
});
var CommentForm = React.createClass({
handleSubmit: function() {
var author = this.refs.author.getDOMNode().value.trim();
var text = this.refs.text.getDOMNode().value.trim();
this.props.onCommentSubmit({author: author, text: text});
this.refs.author.getDOMNode().value = '';
this.refs.text.getDOMNode().value = '';
return false;
},
render: function() {
return (
);
}
});
var CommentBox = React.createClass({
mixins: [ReactFireMixin],
handleCommentSubmit: function(comment) {
// Here we push the update out to Firebase and let ReactFire update this.state.data
this.firebaseRefs["data"].push(comment);
},
getInitialState: function() {
return {
data: []
};
},
componentWillMount: function() {
// Here we bind the component to Firebase and it handles all data updates,
// no need to poll as in the React example.
this.bindAsArray(new Firebase(firebaseUrl + "commentBox"), "data");
},
render: function() {
return (
Comments
);
}
});
React.render(
,
document.getElementById('content')
);