File tree Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -2,5 +2,6 @@ var Reflux = require('reflux');
22
33module . exports = Reflux . createActions ( [
44 'getTopics' ,
5- 'getImages'
5+ 'getImages' ,
6+ 'getImage'
67] ) ;
Original file line number Diff line number Diff line change 11var React = require ( 'react' ) ;
22var Reflux = require ( 'reflux' ) ;
33var ImageStore = require ( '../stores/image-store' ) ;
4+ var Actions = require ( '../actions' ) ;
45
56module . exports = React . createClass ( {
67 mixins : [
78 Reflux . listenTo ( ImageStore , 'onChange' )
89 ] ,
10+ getInitialState : function ( ) {
11+ return {
12+ image : null
13+ }
14+ } ,
15+ componentWillMount : function ( ) {
16+ Actions . getImage ( this . props . params . id ) ;
17+ } ,
918 render : function ( ) {
1019 return < div >
11- I am an image detail.
20+ { this . state . image }
1221 </ div >
1322 } ,
14- onChange : function ( event , image ) {
23+ onChange : function ( ) {
1524 this . setState ( {
16- image : image
25+ image : ImageStore . find ( this . props . params . id )
1726 } ) ;
1827 }
1928} ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,18 @@ module.exports = Reflux.createStore({
1515 this . triggerChange ( ) ;
1616 } . bind ( this ) ) ;
1717 } ,
18+ getImage : function ( id ) {
19+ Api . get ( 'gallery/image/' + id )
20+ . then ( function ( json ) {
21+ if ( this . images ) {
22+ this . images . push ( json . data ) ;
23+ } else {
24+ this . images = [ json . data ] ;
25+ }
26+
27+ this . triggerChange ( ) ;
28+ } . bind ( this ) ) ;
29+ } ,
1830 find : function ( id ) {
1931 var image = _ . findWhere ( this . images , { id : id } ) ;
2032
You can’t perform that action at this time.
0 commit comments