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 11var React = require ( 'react' ) ;
2+ var Reflux = require ( 'reflux' ) ;
23var TopicStore = require ( '../stores/topic-store' ) ;
34
45module . exports = React . createClass ( {
6+ mixins : [
7+ Reflux . listenTo ( TopicStore , 'onChange' )
8+ ] ,
59 getInitialState : function ( ) {
610 return {
711 topics : [ ]
812 }
913 } ,
1014 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 ( ) ;
1916 } ,
2017 render : function ( ) {
2118 return < div className = "list-group" >
@@ -29,5 +26,8 @@ module.exports = React.createClass({
2926 { topic }
3027 </ li >
3128 } ) ;
29+ } ,
30+ onChange : function ( event , topics ) {
31+ this . setState ( { topics : topics } ) ;
3232 }
3333} ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ module.exports = Reflux.createStore({
66 return Api . get ( 'topics/defaults' )
77 . then ( function ( json ) {
88 this . topics = json . data ;
9+ this . triggerChange ( ) ;
910 } . bind ( this ) ) ;
11+ } ,
12+ triggerChange : function ( ) {
13+ this . trigger ( 'change' , this . topics ) ;
1014 }
1115} ) ;
You can’t perform that action at this time.
0 commit comments