Skip to content

Commit c8ea3ad

Browse files
committed
Flux - 20 - Implementing Image Store
1 parent b9a82f7 commit c8ea3ad

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

imgur-client/src/actions.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var Reflux = require('reflux');
22

33
module.exports = Reflux.createActions([
4-
'getTopics'
4+
'getTopics',
5+
'getImages'
56
]);

imgur-client/src/components/topic.jsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
var React = require('react');
2+
var Actions = require('../actions');
3+
var ImageStore = require('../stores/image-store');
4+
var Reflux = require('reflux');
25

36
module.exports = React.createClass({
7+
mixins: [
8+
Reflux.listenTo(ImageStore, 'onChange')
9+
],
10+
getInitialState: function() {
11+
return {
12+
images: []
13+
}
14+
},
15+
componentWillMount: function() {
16+
Actions.getImages(this.props.params.id);
17+
},
418
render: function() {
519
return <div>
6-
I am a topic!
20+
721
</div>
22+
},
23+
onChange: function(event, images) {
24+
this.setState({images: images})
825
}
9-
})
26+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var Reflux = require('reflux');
2+
var Api = require('../utils/api');
3+
var Actions = require('../actions');
4+
5+
module.exports = Reflux.createStore({
6+
listenables: [Actions],
7+
getImages: function(topicId){
8+
Api.get('topics/' + topicId)
9+
.then(function(json){
10+
this.images = json.data;
11+
this.triggerChange();
12+
}.bind(this));
13+
},
14+
triggerChange: function() {
15+
this.trigger('change', this.images);
16+
}
17+
});

0 commit comments

Comments
 (0)