-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
31 lines (27 loc) · 893 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$(function main() {
var $input = $('#textInput'),
$results = $('#results');
// Get all distinct key up events from the input and only fire if long enough and distinct
var keyup = Rx.Observable.fromEvent($input, 'keyup')
.map(function (e) {
return e.target.value;
// transfrom the text from the user input
})
.filter(function (text) {
return text.length > 2; // Only if the text is longer than 2 characters
})
.debounce(750) // make sure user's can't spam us
.distinctUntilChanged(); // Only if the value has changed
keyup.subscribe(
function (data) {
$input.val('')
$results
.append ( data + ' ... ');
},
function (error) {
$results
.empty()
.append($('<li>'))
.text('Error:' + error);
});
}(window, jQuery, Rx));