Skip to content

Commit

Permalink
Flux - 20 - Implementing Image Store
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Jul 5, 2015
1 parent b9a82f7 commit c8ea3ad
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
3 changes: 2 additions & 1 deletion imgur-client/src/actions.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Reflux = require('reflux');

module.exports = Reflux.createActions([
'getTopics'
'getTopics',
'getImages'
]);
21 changes: 19 additions & 2 deletions imgur-client/src/components/topic.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
var React = require('react');
var Actions = require('../actions');
var ImageStore = require('../stores/image-store');
var Reflux = require('reflux');

module.exports = React.createClass({
mixins: [
Reflux.listenTo(ImageStore, 'onChange')
],
getInitialState: function() {
return {
images: []
}
},
componentWillMount: function() {
Actions.getImages(this.props.params.id);
},
render: function() {
return <div>
I am a topic!

</div>
},
onChange: function(event, images) {
this.setState({images: images})
}
})
});
17 changes: 17 additions & 0 deletions imgur-client/src/stores/image-store.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var Reflux = require('reflux');
var Api = require('../utils/api');
var Actions = require('../actions');

module.exports = Reflux.createStore({
listenables: [Actions],
getImages: function(topicId){
Api.get('topics/' + topicId)
.then(function(json){
this.images = json.data;
this.triggerChange();
}.bind(this));
},
triggerChange: function() {
this.trigger('change', this.images);
}
});

0 comments on commit c8ea3ad

Please sign in to comment.