Skip to content

Instantly share code, notes, and snippets.

@AndrewVos
Last active January 2, 2016 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewVos/8345321 to your computer and use it in GitHub Desktop.
Save AndrewVos/8345321 to your computer and use it in GitHub Desktop.
var username = $(".add-user");
var avatar = username.parent().find(".avatar");
username
.asEventStream("keyup")
.map(function(event) { return $(event.target).val() })
.debounce(500)
.flatMapLatest(function(u) {
return Bacon.fromPromise($.ajax("https://api.github.com/users/" + u));
})
.mapError(function() {avatar.attr("src", "")})
.onValue(function(value) {avatar.attr("src", value.avatar_url);});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment