Skip to content

Commit f114d82

Browse files
committed
Flux - 12 - Working with Stores
1 parent f6c8c35 commit f114d82

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

imgur-client/src/components/topic-list.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var React = require('react');
2-
var Api = require('../utils/api');
2+
var TopicStore = require('../stores/topic-store');
33

44
module.exports = React.createClass({
55
getInitialState: function() {
@@ -8,11 +8,13 @@ module.exports = React.createClass({
88
}
99
},
1010
componentWillMount: function() {
11-
Api.get('topics/defaults')
12-
.then(function(data){
11+
TopicStore.getTopics()
12+
.then(function(){
13+
// We have successfully fetched topics
14+
// topics are available on TopicStore.topics
1315
this.setState({
14-
topics: data.data
15-
})
16+
topics: TopicStore.topics
17+
});
1618
}.bind(this));
1719
},
1820
render: function() {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var Api = require('../utils/api');
2+
var Reflux = require('reflux');
3+
4+
module.exports = Reflux.createStore({
5+
getTopics: function() {
6+
return Api.get('topics/defaults')
7+
.then(function(json){
8+
this.topics = json.data;
9+
}.bind(this));
10+
}
11+
});

0 commit comments

Comments
 (0)