Last active
January 10, 2017 09:14
-
-
Save xealgo/a341ae4e7ef4cd3dbb1df9535e22dba1 to your computer and use it in GitHub Desktop.
basic bacon + api request
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
// bacon.fromPromise wrapper | |
let request = function(data) { return Bacon.fromPromise($.ajax(data.url)); } | |
// userdata event stream - sends github api request each time the username text field looses focus. | |
let userdata = $("#username").asEventStream("blur").map(function(event) { | |
let user = $(event.target).val(); | |
return {url: `https://api.github.com/users/${user}`}; | |
}).flatMap(request).log("user stream"); | |
// handle the data response that "request" made. | |
userdata.onValue(function(resp) { | |
alert(resp.name); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment