Last active
January 4, 2017 00:03
-
-
Save andersonleite/42f2f3e58dcdf7126b91a0276103b1a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var requestStream = refreshClickStream.startWith('startup click') | |
.map(function() { | |
return 'https://api.punkapi.com/v2/beers'; | |
}); | |
var responseStream = requestStream | |
.flatMap(function(requestUrl) { | |
return Rx.Observable.fromPromise($.getJSON(requestUrl)); | |
}); | |
function createSuggestionStream(closeClickStream) { | |
return closeClickStream.startWith('startup click') | |
.combineLatest(responseStream, | |
function(click, listBeers) { | |
// console.log(listBeers); | |
return listBeers[Math.floor(Math.random()*listBeers.length)]; | |
} | |
) | |
.merge( | |
refreshClickStream.map(function(){ | |
return null; | |
}) | |
) | |
.startWith(null); | |
} | |
var suggestion1Stream = createSuggestionStream(close1ClickStream); | |
var suggestion2Stream = createSuggestionStream(close2ClickStream); | |
var suggestion3Stream = createSuggestionStream(close3ClickStream); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment