O'Reilly logo

React.js Essentials by Artemij Fedosejev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a store

As we learned earlier, stores manage data in your Flux architecture. They provide that data to the React components. We're going to create a simple store that manages a new tweet that our application receives from Twitter.

Create new folder called stores in our project's ~/snapterest/source/stores directory. Then, create the TweetStore.js file in it:

var AppDispatcher = require('../dispatcher/AppDispatcher'); var EventEmitter = require('events').EventEmitter; var assign = require('object-assign'); var tweet = null; function setTweet(receivedTweet) { tweet = receivedTweet; } function emitChange() { TweetStore.emit('change'); } var TweetStore = assign({}, EventEmitter.prototype, { addChangeListener: function (callback) { this.on('change', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required