Instantly share code, notes, and snippets.

What would you like to do?
var element = document.querySelector('#textinput');
var throttledInput = Rx.Observable.fromEvent(element, 'keyup').select( function (ev) {
// Return text value for each key up
// Throttle input by 500ms
).where( function (text) {
// Only get input more than 2 characters
return text.length > 2;
// Returns only distinct text values
// Combine together with an Ajax call
var serviceCall = function (text) {
// Call service wrapped as an Observable sequence
return queryService(text);
// Trim out of order requests to ensure we only have the latest
// Subscribe to the service call
serviceCall.subscribe( function (results) {
// Handle the results
}, function (err) {
// Handle the errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment