Skip to content

Commit 2528ac5

Browse files
committed
Flux - 28 - Fetching Single Records from a Store
1 parent e606fad commit 2528ac5

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
var React = require('react');
2+
var Reflux = require('reflux');
3+
var ImageStore = require('../stores/image-store');
24

35
module.exports = React.createClass({
6+
mixins: [
7+
Reflux.listenTo(ImageStore, 'onChange')
8+
],
49
render: function() {
510
return <div>
611
I am an image detail.
712
</div>
13+
},
14+
onChange: function(event, image) {
15+
this.setState({
16+
image: image
17+
});
818
}
919
});

imgur-client/src/stores/image-store.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ module.exports = Reflux.createStore({
1515
this.triggerChange();
1616
}.bind(this));
1717
},
18+
find: function(id){
19+
var image = _.findWhere(this.images, {id: id});
20+
21+
if(image) {
22+
return image
23+
} else {
24+
this.getImage(id);
25+
return null
26+
}
27+
},
1828
triggerChange: function() {
1929
this.trigger('change', this.images);
2030
}

0 commit comments

Comments
 (0)