Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
rxjs - Example of Pull vs Push
//Traditional imperative pull based
window.setInterval(() => {
const tweets = getNewTweets();
for(let tweet of tweets){
if(!tweet.message.contains("Greetings!")) continue;
getUserAvatar(tweet.user)
.then(avatar => {
const $avatar = $(`<img />`);
$avatar.attr('src', avatar.url);
$avatars.append($avatar);
});
}
}, 5000);
// Reactive push based
observeTweets()
.filter(s => s.message.contains('Greetings!'))
.flatMap(s => getUserAvatar(s.user))
.map( a => $('< img/>').attr('src', a.url))
.subscribe($avatar => {
$avatars.append($avatar);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment