Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Commit da6c878

Browse files
Adding .min file and fixing docs
1 parent 2a82f19 commit da6c878

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

lib/rx.jquery.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
2-
// This code is licensed by Microsoft Corporation under the terms
3-
// of the MICROSOFT REACTIVE EXTENSIONS FOR JAVASCRIPT AND .NET LIBRARIES License.
4-
// See http://go.microsoft.com/fwlink/?LinkId=186234.
1+
/**
2+
* Copyright 2011 Microsoft Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
515

616
(function(global, $) {
717
var root = global.Rx,

lib/rx.jquery.min.js

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ The goal here is to take the input from our textbox and throttle it in a way tha
4444
var throttledInput = $('#textInput')
4545
.keyupAsObservable()
4646

47-
Since we're only interested in the text, we'll use the [select](http://msdn.microsoft.com/en-us/library/hh244311(v=VS.103).aspx) method to take the event object and return the target's value.
47+
Since we're only interested in the text, we'll use the [select]((http://msdn.microsoft.com/en-us/library/hh244311(v=VS.103).aspx)) method to take the event object and return the target's value.
4848

4949
.select( function (ev) {
5050
return $(ev.target).val();
5151
})
5252

53-
We're also not interested in query terms less than two letters, so we'll trim that user input by using the [where](http://msdn.microsoft.com/en-us/library/hh229267(v=VS.103).aspx) method returning whether the string length is appropriate.
53+
We're also not interested in query terms less than two letters, so we'll trim that user input by using the [where]((http://msdn.microsoft.com/en-us/library/hh229267(v=VS.103).aspx)) method returning whether the string length is appropriate.
5454

5555
.where( function (text) {
5656
return text.length > 2;
5757
})
5858

59-
We also want to slow down the user input a little bit so that the external service won't be flooded with requests. To do that, we'll use the [throttle](http://msdn.microsoft.com/en-us/library/hh229298(v=VS.103).aspx) method with a timeout of 500 milliseconds, which will ignore your fast typing and only return a value after you have paused for that time span.
59+
We also want to slow down the user input a little bit so that the external service won't be flooded with requests. To do that, we'll use the [throttle]((http://msdn.microsoft.com/en-us/library/hh229298(v=VS.103).aspx))method with a timeout of 500 milliseconds, which will ignore your fast typing and only return a value after you have paused for that time span.
6060

6161
.throttle(500)
6262

@@ -77,7 +77,7 @@ Putting it all together, our throttledInput looks like the following:
7777
.throttle(500)
7878
.distinctUntilChanged();
7979

80-
Now that we have the throttled input from the textbox, we need to query our service, in this case, the Wikipedia API, for suggestions based upon our input. To do this, we'll create a function called searchWikipedia which calls the jQuery.ajaxAsObservable method which wraps the existing jQuery Ajax request in an RxJS [AsyncSubject](http://msdn.microsoft.com/en-us/library/hh229363(v=VS.103).aspx).
80+
Now that we have the throttled input from the textbox, we need to query our service, in this case, the Wikipedia API, for suggestions based upon our input. To do this, we'll create a function called searchWikipedia which calls the jQuery.ajaxAsObservable method which wraps the existing jQuery Ajax request in an RxJS [AsyncSubject]((http://msdn.microsoft.com/en-us/library/hh229363(v=VS.103).aspx)).
8181

8282
function searchWikipedia(term) {
8383
return $.ajaxAsObservable({
@@ -89,7 +89,7 @@ Now that we have the throttled input from the textbox, we need to query our serv
8989
});
9090
}
9191

92-
Now that the Wikipedia Search has been wrapped, we can tie together throttled input and our service call. In this case, we will call select on the throttledInput to then take the text from our textInput and then use it to query Wikipedia, filtering out empty records. Finally, to deal with concurrency issues, we'll need to ensure we're getting only the latest value. Issues can arise with asynchronous programming where an earlier value, if not cancelled properly, can be returned before the latest value is returned, thus causing bugs. To ensure that this doesn't happen, we have the [switchLatest](http://msdn.microsoft.com/en-us/library/hh229197(v=VS.103).aspx) method which returns only the latest value.
92+
Now that the Wikipedia Search has been wrapped, we can tie together throttled input and our service call. In this case, we will call select on the throttledInput to then take the text from our textInput and then use it to query Wikipedia, filtering out empty records. Finally, to deal with concurrency issues, we'll need to ensure we're getting only the latest value. Issues can arise with asynchronous programming where an earlier value, if not cancelled properly, can be returned before the latest value is returned, thus causing bugs. To ensure that this doesn't happen, we have the [switchLatest]((http://msdn.microsoft.com/en-us/library/hh229197(v=VS.103).aspx)) method which returns only the latest value.
9393

9494
var suggestions = throttledInput.select( function (text) {
9595
return searchWikipedia(text);

0 commit comments

Comments
 (0)