File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 1
1
var React = require ( 'react' ) ;
2
+ var Reflux = require ( 'reflux' ) ;
2
3
var TopicStore = require ( '../stores/topic-store' ) ;
3
4
4
5
module . exports = React . createClass ( {
6
+ mixins : [
7
+ Reflux . listenTo ( TopicStore , 'onChange' )
8
+ ] ,
5
9
getInitialState : function ( ) {
6
10
return {
7
11
topics : [ ]
8
12
}
9
13
} ,
10
14
componentWillMount : function ( ) {
11
- TopicStore . getTopics ( )
12
- . then ( function ( ) {
13
- // We have successfully fetched topics
14
- // topics are available on TopicStore.topics
15
- this . setState ( {
16
- topics : TopicStore . topics
17
- } ) ;
18
- } . bind ( this ) ) ;
15
+ TopicStore . getTopics ( ) ;
19
16
} ,
20
17
render : function ( ) {
21
18
return < div className = "list-group" >
@@ -29,5 +26,8 @@ module.exports = React.createClass({
29
26
{ topic }
30
27
</ li >
31
28
} ) ;
29
+ } ,
30
+ onChange : function ( event , topics ) {
31
+ this . setState ( { topics : topics } ) ;
32
32
}
33
33
} ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ module.exports = Reflux.createStore({
6
6
return Api . get ( 'topics/defaults' )
7
7
. then ( function ( json ) {
8
8
this . topics = json . data ;
9
+ this . triggerChange ( ) ;
9
10
} . bind ( this ) ) ;
11
+ } ,
12
+ triggerChange : function ( ) {
13
+ this . trigger ( 'change' , this . topics ) ;
10
14
}
11
15
} ) ;
You can’t perform that action at this time.
0 commit comments