The posts store

At this point, the posts store allows fetching a single post or all of the posts in the system. This will be revised to fetch batches of posts in Chapter 7, React Blog App Part 4 – Infinite Scroll and Search, for the infinite scroll loading feature.

Here's the posts store source:

File: js/stores/posts.js

import Reflux from 'reflux'; import Actions from 'appRoot/actions'; import Request from 'superagent'; import Config from 'appRoot/appConfig'; export default Reflux.createStore({ listenables: Actions, endpoint: Config.apiRoot + '/posts', posts: [], // called when mixin is used to init the component state getInitialState: function () { return this.posts; }, init: function () { Request .get(this.endpoint) .end(function (err, res) { ...

Get React: Building Modern Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.