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');
2
2
3
3
module . exports = Reflux . createActions ( [
4
4
'getTopics' ,
5
- 'getImages'
5
+ 'getImages' ,
6
+ 'getImage'
6
7
] ) ;
Original file line number Diff line number Diff line change 1
1
var React = require ( 'react' ) ;
2
2
var Reflux = require ( 'reflux' ) ;
3
3
var ImageStore = require ( '../stores/image-store' ) ;
4
+ var Actions = require ( '../actions' ) ;
4
5
5
6
module . exports = React . createClass ( {
6
7
mixins : [
7
8
Reflux . listenTo ( ImageStore , 'onChange' )
8
9
] ,
10
+ getInitialState : function ( ) {
11
+ return {
12
+ image : null
13
+ }
14
+ } ,
15
+ componentWillMount : function ( ) {
16
+ Actions . getImage ( this . props . params . id ) ;
17
+ } ,
9
18
render : function ( ) {
10
19
return < div >
11
- I am an image detail.
20
+ { this . state . image }
12
21
</ div >
13
22
} ,
14
- onChange : function ( event , image ) {
23
+ onChange : function ( ) {
15
24
this . setState ( {
16
- image : image
25
+ image : ImageStore . find ( this . props . params . id )
17
26
} ) ;
18
27
}
19
28
} ) ;
Original file line number Diff line number Diff line change @@ -15,6 +15,18 @@ module.exports = Reflux.createStore({
15
15
this . triggerChange ( ) ;
16
16
} . bind ( this ) ) ;
17
17
} ,
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
+ } ,
18
30
find : function ( id ) {
19
31
var image = _ . findWhere ( this . images , { id : id } ) ;
20
32
You can’t perform that action at this time.
0 commit comments