Skip to content

Commit

Permalink
Flux - 32 - Listening to Many Changes in a Component
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Jul 5, 2015
1 parent 43e3865 commit a3a6207
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 10 additions & 0 deletions imgur-client/src/components/comment-box.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var React = require('react');

module.exports = React.createClass({
render: function(){
return <div>
I am a comment box.
{this.props.comments}
</div>
}
});
20 changes: 17 additions & 3 deletions imgur-client/src/components/image-detail.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
var React = require('react');
var Reflux = require('reflux');
var ImageStore = require('../stores/image-store');
var CommentStore = require('../stores/comment-store');
var Actions = require('../actions');
var CommentBox = require('./comment-box');

module.exports = React.createClass({
mixins: [
Reflux.listenTo(ImageStore, 'onChange')
Reflux.listenTo(ImageStore, 'onChange'),
Reflux.listenTo(CommentStore, 'onChange')
],
getInitialState: function() {
return {
image: null
image: null,
comment: null
}
},
componentWillMount: function() {
Expand All @@ -33,8 +37,17 @@ module.exports = React.createClass({
<h5>{this.state.image.description}</h5>
</div>
</div>
<h3>Comments</h3>
{this.renderComments()}
</div>
},
renderComments: function() {
if(!this.state.comments){
return null
}

return <CommentBox comments={this.state.comments} />
},
renderImage: function() {
if(this.state.image.animated) {
return <video preload="auto" autoPlay="autoplay" loop="loop" webkit-playsinline>
Expand All @@ -46,7 +59,8 @@ module.exports = React.createClass({
},
onChange: function() {
this.setState({
image: ImageStore.find(this.props.params.id)
image: ImageStore.find(this.props.params.id),
comments: CommentStore.comment
});
}
});

0 comments on commit a3a6207

Please sign in to comment.