Skip to content

Instantly share code, notes, and snippets.

@JamesTheHacker
Created October 12, 2017 16:19
Show Gist options
  • Save JamesTheHacker/52db6bb18ea7ca38f54afdc8907b07e9 to your computer and use it in GitHub Desktop.
Save JamesTheHacker/52db6bb18ea7ca38f54afdc8907b07e9 to your computer and use it in GitHub Desktop.
// Subscribe to receive notifications
store.subscribe(action => {
// Check the type of action
if(action == ‘TWEETS_RECEIVED’) {
// Clear notification
document.getElementById(‘notification’).innerText = ‘’;
// Construct the HTML for the tweets list
const tweets = store.getState().tweets.map(tweet => {
return`
<li>
<p class=”username”>${tweet.username}</p>
<p class=”message”>${tweet.message}</p>
</li>
`;
})
// Add tweets to UI
document.getElementById(‘tweets’).innerHTML = tweets;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment