Skip to content

Commit

Permalink
Used Fetchr to get the feed posts
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxoncreed committed Aug 19, 2015
1 parent 44ad21f commit 76b2651
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
18 changes: 11 additions & 7 deletions actions/getPosts.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
var posts = require('../dummyData/posts.json');

module.exports = function (context, payload, callback) {
context.dispatch('POSTS_RECEIVED', {
posts: posts
module.exports = function (context, payload, callback) {
context.service.read('posts', {}, {}, function(err, posts) {
if (err) {
callback(err);
} else {
context.dispatch('POSTS_RECEIVED', {
posts: posts
});
callback();
}
});
callback();
};
};
7 changes: 7 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ var RouteStore = require('./stores/RouteStore');
var UserStore = require('./stores/UserStore');
var FeedStore = require('./stores/FeedStore');

var fetchr = require('fluxible-plugin-fetchr');
var fetchrInstance = fetchr({
xhrPath: '/api'
});

// create new fluxible instance
var app = new Fluxible({
component: Application
});

app.plug(fetchrInstance);

// register stores
app.registerStore(RouteStore);
app.registerStore(ApplicationStore);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"fluxible": "^0.5.0",
"fluxible-addons-react": "^0.1.6",
"fluxible-app": "^0.1.5",
"fluxible-plugin-fetchr": "^0.3.0",
"fluxible-plugin-fetchr": "^0.3.6",
"fluxible-router": "^0.2.0",
"react": "^0.13.0",
"serialize-javascript": "^1.0.0",
Expand Down
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ var env = process.env.NODE_ENV;

var debug = debugLib('fluxible-template');

/* Regeister Services */
app.getPlugin('FetchrPlugin').registerService(require('./services/PostService'));

var server = express();
server.use('/public', express.static(path.join(__dirname, '/build')));
server.use(compression());
Expand Down
9 changes: 9 additions & 0 deletions services/PostService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var posts = require('../dummyData/posts.json');

module.exports = {
name: "posts",
read: function(req, resource, params, config, callback) {
// We would do some kind of database call here.
callback(null, posts);
}
}

0 comments on commit 76b2651

Please sign in to comment.