June 2016
Intermediate to advanced
910 pages
18h 59m
English
Let's create a new folder called actions in our project's ~/snapterest/source/actions directory. Then, create the TweetActionCreators.js file in it:
var AppDispatcher = require('../dispatcher/AppDispatcher');
function receiveTweet(tweet) {
var action = {
type: 'receive_tweet',
tweet: tweet
};
AppDispatcher.dispatch(action);
}
module.exports = {
receiveTweet: receiveTweet
};Our action creators will need a dispatcher to dispatch the actions. We will import AppDispatcher that we created previously:
var AppDispatcher = require('../dispatcher/AppDispatcher');Then, we create our first action creator receiveTweet():
function receiveTweet(tweet) { var action = { type: 'receive_tweet', tweet: tweet }; AppDispatcher.dispatch(action); ...Read now
Unlock full access