Skip to content

Instantly share code, notes, and snippets.

@xealgo
Last active January 10, 2017 09:14
Show Gist options
  • Save xealgo/a341ae4e7ef4cd3dbb1df9535e22dba1 to your computer and use it in GitHub Desktop.
Save xealgo/a341ae4e7ef4cd3dbb1df9535e22dba1 to your computer and use it in GitHub Desktop.
basic bacon + api request
// 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