From 2528ac5875793ff75bdc047a793c44a20b7965e6 Mon Sep 17 00:00:00 2001 From: stephen grider Date: Sun, 5 Jul 2015 16:09:01 -0700 Subject: [PATCH] Flux - 28 - Fetching Single Records from a Store --- imgur-client/src/components/image-detail.jsx | 10 ++++++++++ imgur-client/src/stores/image-store.jsx | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/imgur-client/src/components/image-detail.jsx b/imgur-client/src/components/image-detail.jsx index 8e066fb..39146a4 100644 --- a/imgur-client/src/components/image-detail.jsx +++ b/imgur-client/src/components/image-detail.jsx @@ -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
I am an image detail.
+ }, + onChange: function(event, image) { + this.setState({ + image: image + }); } }); diff --git a/imgur-client/src/stores/image-store.jsx b/imgur-client/src/stores/image-store.jsx index 1e5c4a9..961bd11 100644 --- a/imgur-client/src/stores/image-store.jsx +++ b/imgur-client/src/stores/image-store.jsx @@ -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); }