Book Image

React.js Essentials

By : Artemij Fedosejev
Book Image

React.js Essentials

By: Artemij Fedosejev

Overview of this book

Table of Contents (18 chapters)
React.js Essentials
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating CollectionActionCreators


Navigate to ~/snapterest/source/actions/ and create the CollectionActionCreators.js file:

var AppDispatcher = require('../dispatcher/AppDispatcher');

module.exports = {

  addTweetToCollection: function (tweet) {

    var action = {
      type: 'add_tweet_to_collection',
      tweet: tweet
    };

    AppDispatcher.dispatch(action);
  },

  removeTweetFromCollection: function (tweetId) {

    var action = {
      type: 'remove_tweet_from_collection',
      tweetId: tweetId
    };

    AppDispatcher.dispatch(action);
  },

  removeAllTweetsFromCollection: function () {

    var action = {
      type: 'remove_all_tweets_from_collection'
    };

    AppDispatcher.dispatch(action);
  },

  setCollectionName: function (collectionName) {

    var action = {
      type: 'set_collection_name',
      collectionName: collectionName
    };

    AppDispatcher.dispatch(action);
  }

};

For each action that we handle in CollectionStore, we have an action creator function...