Creating CollectionStore

Not only does Snapterest store the latest tweet, but it also stores a collection of tweets that the user creates. Let's refactor this feature with Flux.

First, let's create a collection store. Navigate to the ~/snapterest/source/stores/ directory and create the CollectionStore.js file:

var AppDispatcher = require('../dispatcher/AppDispatcher'); var EventEmitter = require('events').EventEmitter; var assign = require('object-assign'); var CHANGE_EVENT = 'change'; var collectionTweets = {}; var collectionName = 'new'; function addTweetToCollection(tweet) { collectionTweets[tweet.id] = tweet; } function removeTweetFromCollection(tweetId) { delete collectionTweets[tweetId]; } function removeAllTweetsFromCollection() { collectionTweets ...

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.