Skip to content

Commit

Permalink
Flux - 28 - Fetching Single Records from a Store
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Jul 5, 2015
1 parent e606fad commit 2528ac5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions imgur-client/src/components/image-detail.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
var React = require('react');
var Reflux = require('reflux');
var ImageStore = require('../stores/image-store');

module.exports = React.createClass({
mixins: [
Reflux.listenTo(ImageStore, 'onChange')
],
render: function() {
return <div>
I am an image detail.
</div>
},
onChange: function(event, image) {
this.setState({
image: image
});
}
});
10 changes: 10 additions & 0 deletions imgur-client/src/stores/image-store.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ module.exports = Reflux.createStore({
this.triggerChange();
}.bind(this));
},
find: function(id){
var image = _.findWhere(this.images, {id: id});

if(image) {
return image
} else {
this.getImage(id);
return null
}
},
triggerChange: function() {
this.trigger('change', this.images);
}
Expand Down

0 comments on commit 2528ac5

Please sign in to comment.