Creating CollectionStore

Not only does Snapterest store the latest tweet, but it also stores a collection of tweets that users create. 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:

import AppDispatcher from ‘../dispatcher/AppDispatcher’; import { EventEmitter } from ‘events’; const CHANGE_EVENT = ‘change’; let collectionTweets = {}; let collectionName = ‘new’; function addTweetToCollection(tweet) { collectionTweets[tweet.id] = tweet; } function removeTweetFromCollection(tweetId) { delete collectionTweets[tweetId]; } function removeAllTweetsFromCollection() { collectionTweets = {}; } function setCollectionName(name) { collectionName ...

Get React 16 Essentials - Second Edition 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.