Created
March 3, 2014 21:49
-
-
Save mattpodwysocki/9335376 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
// Submit the form when the submit button is clicked | |
var signUpCommand = function(emailAddress) { | |
var promise = $.ajax({ | |
type: 'POST', | |
url: '...', | |
data: JSON.stringify({ | |
'email': emailAddress | |
}), | |
contentType: 'application/json; charset=utf-8', | |
dataType: 'json' | |
}).promise(); | |
return Rx.Observable.fromPromise(promise); | |
}; | |
var submitButtonClickedSignal = Rx.Observable.fromEvent($submit, 'click'); | |
var submissionSignal = submitButtonClickedSignal | |
.flatMapLatest(function(e) { | |
return signUpCommand($input.val()); | |
}); | |
submissionSignal | |
.subscribe(function(data) { | |
console.log(data); | |
}, function(error) { | |
console.error(error); | |
}, function() { | |
// This never gets called | |
console.log('onCompleted'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment