Skip to content

Commit a3a6207

Browse files
committed
Flux - 32 - Listening to Many Changes in a Component
1 parent 43e3865 commit a3a6207

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var React = require('react');
2+
3+
module.exports = React.createClass({
4+
render: function(){
5+
return <div>
6+
I am a comment box.
7+
{this.props.comments}
8+
</div>
9+
}
10+
});

imgur-client/src/components/image-detail.jsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
var React = require('react');
22
var Reflux = require('reflux');
33
var ImageStore = require('../stores/image-store');
4+
var CommentStore = require('../stores/comment-store');
45
var Actions = require('../actions');
6+
var CommentBox = require('./comment-box');
57

68
module.exports = React.createClass({
79
mixins: [
8-
Reflux.listenTo(ImageStore, 'onChange')
10+
Reflux.listenTo(ImageStore, 'onChange'),
11+
Reflux.listenTo(CommentStore, 'onChange')
912
],
1013
getInitialState: function() {
1114
return {
12-
image: null
15+
image: null,
16+
comment: null
1317
}
1418
},
1519
componentWillMount: function() {
@@ -33,8 +37,17 @@ module.exports = React.createClass({
3337
<h5>{this.state.image.description}</h5>
3438
</div>
3539
</div>
40+
<h3>Comments</h3>
41+
{this.renderComments()}
3642
</div>
3743
},
44+
renderComments: function() {
45+
if(!this.state.comments){
46+
return null
47+
}
48+
49+
return <CommentBox comments={this.state.comments} />
50+
},
3851
renderImage: function() {
3952
if(this.state.image.animated) {
4053
return <video preload="auto" autoPlay="autoplay" loop="loop" webkit-playsinline>
@@ -46,7 +59,8 @@ module.exports = React.createClass({
4659
},
4760
onChange: function() {
4861
this.setState({
49-
image: ImageStore.find(this.props.params.id)
62+
image: ImageStore.find(this.props.params.id),
63+
comments: CommentStore.comment
5064
});
5165
}
5266
});

0 commit comments

Comments
 (0)