First, we’ll create a new utility module called WebAPIUtils
. Create the WebAPIUtils.js
file in the ~/snapterest/source/utils/
directory:
import SnapkiteStreamClient from ‘snapkite-stream-client’; import { receiveTweet } from ‘../actions/TweetActionCreators’; function initializeStreamOfTweets() { SnapkiteStreamClient.initializeStream(receiveTweet); } export { initializeStreamOfTweets };
In this utility module, we first import the SnapkiteStreamClient
library and TweetActionCreators
. Then, we create the initializeStreamOfTweets()
function that initializes a stream of new tweets, just like in the componentDidMount()
method of the Stream
component. Except with one key difference: whenever SnapkiteStreamClient
receives a new tweet, it calls the TweetActionCreators.receiveTweet
method that passes a new tweet to it as an argument:
SnapkiteStreamClient.initializeStream(receiveTweet);
Remember that the receiveTweet
function expects to receive a tweet
argument:
function...