June 2016
Intermediate to advanced
910 pages
18h 59m
English
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) { ...Read now
Unlock full access