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

Commit 3cfb15e

Browse files
Version bump to 1.1.4
1 parent 1908f89 commit 3cfb15e

File tree

4 files changed

+120
-115
lines changed

4 files changed

+120
-115
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Rx-jQuery",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"main": "rx.jquery.js",
55
"dependencies": {
66
"rxjs": "*"

nuget/RxJS-Bridges-jQuery/RxJS-Bridges-jQuery.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<id>RxJS-Bridges-jQuery</id>
55
<title>Reactive Extensions for JavaScript - Bridges to jQuery </title>
66
<!-- Automatically updated by build, keeping fixed dev build number here in case of local build -->
7-
<version>1.1.3</version>
7+
<version>1.1.4</version>
88
<authors>Microsoft Corporation</authors>
99
<description>This project provides Reactive Extensions for JavaScript (RxJS) bindings for jQuery to abstract over the event binding, Ajax and Deferreds.</description>
1010
<projectUrl>https://github.com/Reactive-Extensions/rxjs-jquery</projectUrl>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "rx-jquery",
33
"title": "Reactive Extensions for JavaScript bindings for jQuery",
44
"description": "Library for composing asynchronous and event-based operations in JavaScript extending the jQuery library",
5-
"version": "1.1.3",
5+
"version": "1.1.4",
66
"homepage": "https://github.com/Reactive-Extensions/rxjs-jquery",
77
"author": {
88
"name": "MS Open Tech",

readme.md

Lines changed: 117 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
RxJS-jQuery <sup>2.0</sup> - jQuery Bindings for the Reactive Extensions for JavaScript
1+
RxJS-jQuery <sup>1.1</sup> - jQuery Bindings for the Reactive Extensions for JavaScript
22
==========================================================
33
## OVERVIEW
44

@@ -27,7 +27,7 @@ To download the source of the jQuery Bindings for the Reactive Extensions for Ja
2727

2828
jam install rx-jquery
2929

30-
### Installing with NuGet
30+
### Installing with [NuGet](http://nuget.org)
3131

3232
PM> Install-Package RxJS-Bridges-jQuery
3333

@@ -38,8 +38,9 @@ Let's walk through a simple yet powerful example of the Reactive Extensions for
3838
We'll start out with a basic skeleton for our application with script references to jQuery, RxJS, RxJS Time-based methods, and the RxJS Bindings for jQuery, along with a textbox for input and a list for our results.
3939

4040
<script type="text/javascript" src="jquery.js"></script>
41-
<script type="text/javascript" src="rx.min.js"></script>
42-
<script type="text/javascript" src="rx.time.min.js"></script>
41+
<script type="text/javascript" src="rx.js"></script>
42+
<script type="text/javascript" src="rx.binding.js"></script>
43+
<script type="text/javascript" src="rx.time.js"></script>
4344
<script type="text/javascript" src="rx-jquery.js"><script>
4445
<script type="text/javascript">
4546
$(function () {
@@ -53,136 +54,140 @@ We'll start out with a basic skeleton for our application with script references
5354

5455
The goal here is to take the input from our textbox and throttle it in a way that it doesn't overload the service with requests. To do that, we'll get the reference to the textInput using jQuery, then bind to the 'keyup' event using the keyupAsObservable method which then takes the jQuery object and transforms it into an RxJS Observable.
5556

56-
var throttledInput = $('#textInput')
57-
.keyupAsObservable()
58-
59-
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.
60-
61-
.select( function (ev) {
62-
return $(ev.target).val();
63-
})
64-
65-
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.
66-
67-
.where( function (text) {
68-
return text.length > 2;
69-
})
70-
71-
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.
72-
73-
.throttle(500)
74-
57+
```js
58+
var throttledInput = $('#textInput')
59+
.keyupAsObservable()
60+
```
61+
Since we're only interested in the text, we'll use the `map` method to take the event object and return the target's value.
62+
```js
63+
.map( function (ev) {
64+
return $(ev.target).val();
65+
})
66+
```
67+
We're also not interested in query terms less than two letters, so we'll trim that user input by using the `filter` method returning whether the string length is appropriate.
68+
```js
69+
.filter( function (text) {
70+
return text.length > 2;
71+
})
72+
```
73+
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` 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.
74+
```js
75+
.throttle(500 /* ms */)
76+
```
7577
Lastly, we only want distinct values in our input stream, so we can ignore requests that are not unique, for example if I copy and paste the same value twice, the request will be ignored.
76-
77-
.distinctUntilChanged();
78-
78+
```js
79+
.distinctUntilChanged();
80+
```
7981
Putting it all together, our throttledInput looks like the following:
80-
81-
var throttledInput = $('#textInput')
82-
.keyupAsObservable()
83-
.select( function (ev) {
84-
return $(ev.target).val();
85-
})
86-
.where( function (text) {
87-
return text.length > 2;
88-
})
89-
.throttle(500)
90-
.distinctUntilChanged();
91-
92-
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).
93-
94-
function searchWikipedia(term) {
95-
return $.ajaxAsObservable({
96-
url: 'http://en.wikipedia.org/w/api.php',
97-
data: { action: 'opensearch',
98-
search: term,
99-
format: 'json' }
100-
dataType: 'jsonp'
101-
});
102-
}
103-
104-
Now that the Wikipedia Search has been wrapped, we can tie together throttled input and our service call. 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.
105-
106-
var suggestions = throttledInput.select( function (text) {
107-
return searchWikipedia(text);
82+
```js
83+
var throttledInput = $('#textInput')
84+
.keyupAsObservable()
85+
.map( function (ev) {
86+
return $(ev.target).val();
10887
})
109-
.switchLatest();
110-
88+
.filter( function (text) {
89+
return text.length > 2;
90+
})
91+
.throttle(500)
92+
.distinctUntilChanged();
93+
```
94+
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 `Rx.AsyncSubject`.
95+
```js
96+
function searchWikipedia(term) {
97+
return $.ajaxAsObservable({
98+
url: 'http://en.wikipedia.org/w/api.php',
99+
data: { action: 'opensearch',
100+
search: term,
101+
format: 'json' }
102+
dataType: 'jsonp'
103+
});
104+
}
105+
```
106+
Now that the Wikipedia Search has been wrapped, we can tie together throttled input and our service call. 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 `flatMap` method which returns only the latest value.
107+
```js
108+
var suggestions = throttledInput.flatMapLatest( function (text) {
109+
return searchWikipedia(text);
110+
});
111+
```
111112
Finally, we'll subscribe to our observable by calling subscribe which will receive the results and put them into an unordered list. We'll also handle errors, for example if the server is unavailable by passing in a second function which handles the errors.
113+
```js
114+
var selector = $('#results');
112115

113-
suggestions.subscribe( function (data) {
114-
var selector = $('#results');
116+
var subscription = suggestions.subscribe(
117+
function (data) {
115118
selector.clear();
116119
$.each(data[1], function (_, text) {
117120
$('<li>' + text + '</li>').appendTo(selector);
118121
});
119-
}, function (e) {
122+
},
123+
function (e) {
120124
selector.clear();
121125
$('<li>Error: ' + e + '</li>').appendTo('#results');
122-
});
123-
126+
}
127+
);
128+
```
124129
We've only scratched the surface of this library in this simple example.
125130

126131
### Implemented Bindings
127132

128133
* jQuery Events
129-
* [bind](http://api.jquery.com/bind/) - bindAsObservable
130-
* [delegate](http://api.jquery.com/delegate/) - delegateAsObservable
131-
* [live](http://api.jquery.com/live/) - liveAsObservable
132-
* [on](http://api.jquery.com/on/) - onAsObservable
133-
* [one](http://api.jquery.com/one/) - oneAsObservable
134+
* [`bind`](http://api.jquery.com/bind/) - `bindAsObservable`
135+
* [`delegate`](http://api.jquery.com/delegate/) - `delegateAsObservable`
136+
* [`live`](http://api.jquery.com/live/) - `liveAsObservable`
137+
* [`on`](http://api.jquery.com/on/) - `onAsObservable`
138+
* [`one`](http://api.jquery.com/one/) - `oneAsObservable`
134139

135140
* jQuery Event Shortcuts
136-
* [change](http://api.jquery.com/change/) - changeAsObservable
137-
* [click](http://api.jquery.com/click/) - clickAsObservable
138-
* [dblclick](http://api.jquery.com/dblclick/) - dblclickAsObservable
139-
* [focus](http://api.jquery.com/focus/) - focusAsObservable
140-
* [focusin](http://api.jquery.com/focusin/) - focusinAsObservable
141-
* [focusout](http://api.jquery.com/focusout/) - focusoutAsObservable
142-
* [hover](http://api.jquery.com/hover/) - hoverAsObservable
143-
* [keydown](http://api.jquery.com/keydown/) - keydownAsObservable
144-
* [keypress](http://api.jquery.com/keypress/) - keypressAsObservable
145-
* [keyup](http://api.jquery.com/keyup/) - keyupAsObservable
146-
* [load](http://api.jquery.com/load/) - loadAsObservable
147-
* [mousedown](http://api.jquery.com/mousedown/) - mousedownAsObservable
148-
* [mouseenter](http://api.jquery.com/mouseenter/) - mouseenterAsObservable
149-
* [mouseleave](http://api.jquery.com/mouseleave/) - mouseleaveAsObservable
150-
* [mousemove](http://api.jquery.com/mousemove/) - mousemoveAsObservable
151-
* [mouseout](http://api.jquery.com/mouseout/) - mouseoutAsObservable
152-
* [mouseover](http://api.jquery.com/mouseover/) - mouseoverAsObservable
153-
* [mouseup](http://api.jquery.com/mouseup/) - mouseupAsObservable
154-
* [ready](http://api.jquery.com/ready/) - readyAsObservable
155-
* [resize](http://api.jquery.com/resize/) - resizeAsObservable
156-
* [scroll](http://api.jquery.com/scroll/) - scrollAsObservable
157-
* [select](http://api.jquery.com/select/) - selectAsObservable
158-
* [submit](http://api.jquery.com/submit/) - submitAsObservable
159-
* [unload](http://api.jquery.com/unload/) - unloadAsObservable
141+
* [`change`](http://api.jquery.com/change/) - `changeAsObservable`
142+
* [`click`](http://api.jquery.com/click/) - `clickAsObservable`
143+
* [`dblclick`](http://api.jquery.com/dblclick/) - `dblclickAsObservable`
144+
* [`focus`](http://api.jquery.com/focus/) - `focusAsObservable`
145+
* [`focusin`](http://api.jquery.com/focusin/) - `focusinAsObservable`
146+
* [`focusout`](http://api.jquery.com/focusout/) - `focusoutAsObservable`
147+
* [`hover`](http://api.jquery.com/hover/) - `hoverAsObservable`
148+
* [`keydown`](http://api.jquery.com/keydown/) - `keydownAsObservable`
149+
* [`keypress`](http://api.jquery.com/keypress/) - `keypressAsObservable`
150+
* [`keyup`](http://api.jquery.com/keyup/) - `keyupAsObservable`
151+
* [`load`](http://api.jquery.com/load/) - `loadAsObservable`
152+
* [`mousedown`](http://api.jquery.com/mousedown/) - `mousedownAsObservable`
153+
* [`mouseenter`](http://api.jquery.com/mouseenter/) - `mouseenterAsObservable`
154+
* [`mouseleave`](http://api.jquery.com/mouseleave/) - `mouseleaveAsObservable`
155+
* [`mousemove`](http://api.jquery.com/mousemove/) - `mousemoveAsObservable`
156+
* [`mouseout`](http://api.jquery.com/mouseout/) - `mouseoutAsObservable`
157+
* [`mouseover`](http://api.jquery.com/mouseover/) - `mouseoverAsObservable`
158+
* [`mouseup`](http://api.jquery.com/mouseup/) - `mouseupAsObservable`
159+
* [`ready`](http://api.jquery.com/ready/) - `readyAsObservable`
160+
* [`resize`](http://api.jquery.com/resize/) - `resizeAsObservable`
161+
* [`scroll`](http://api.jquery.com/scroll/) - `scrollAsObservable`
162+
* [`select`](http://api.jquery.com/select/) - `selectAsObservable`
163+
* [`submit`](http://api.jquery.com/submit/) - `submitAsObservable`
164+
* [`unload`](http://api.jquery.com/unload/) - `unloadAsObservable`
160165

161166
* jQuery Effects
162-
* [animate](http://api.jquery.com/animate/) - animateAsObservable
163-
* [fadeIn](http://api.jquery.com/fadeIn/) - fadeInAsObservable
164-
* [fadeOut](http://api.jquery.com/fadeOut/) - fadeOutAsObservable
165-
* [fadeTo](http://api.jquery.com/fadeTo/) - fadeToAsObservable
166-
* [fadeToggle](http://api.jquery.com/fadeToggle/) - fadeToggleAsObservable
167-
* [hide](http://api.jquery.com/hide/) - hideAsObservable
168-
* [show](http://api.jquery.com/show/) - showAsObservable
169-
* [slideDown](http://api.jquery.com/slideDown/) - slideDownAsObservable
170-
* [slideToggle](http://api.jquery.com/slideToggle/) - slideToggleAsObservable
171-
* [slideUp](http://api.jquery.com/slideUp/) - slideUpAsObservable
167+
* [`animate`](http://api.jquery.com/animate/) - `animateAsObservable`
168+
* [`fadeIn`](http://api.jquery.com/fadeIn/) - `fadeInAsObservable`
169+
* [`fadeOut`](http://api.jquery.com/fadeOut/) - `fadeOutAsObservable`
170+
* [`fadeTo`](http://api.jquery.com/fadeTo/) - `fadeToAsObservable`
171+
* [`fadeToggle`](http://api.jquery.com/fadeToggle/) - `fadeToggleAsObservable`
172+
* [`hide`](http://api.jquery.com/hide/) - `hideAsObservable`
173+
* [`show`](http://api.jquery.com/show/) - `showAsObservable`
174+
* [`slideDown`](http://api.jquery.com/slideDown/) - `slideDownAsObservable`
175+
* [`slideToggle`](http://api.jquery.com/slideToggle/) - `slideToggleAsObservable`
176+
* [`slideUp`](http://api.jquery.com/slideUp/) - `slideUpAsObservable`
172177

173178
* Ajax Methods
174-
* [ajax](http://api.jquery.com/jQuery.ajax/) - ajaxAsObservable
175-
* [get](http://api.jquery.com/jQuery.get/) - getAsObservable
176-
* [getJSON](http://api.jquery.com/jQuery.getJSON/) - getJSONAsObservable
177-
* [getScript](http://api.jquery.com/jQuery.getScript/) - getScriptAsObservable
178-
* [post](http://api.jquery.com/jQuery.post/) - postAsObservable
179-
180-
* [Deferred Object](http://api.jquery.com/category/deferred-object/)
181-
* Deferred.toObservable
182-
* Rx.Observable.toDeferred
183-
184-
* [Callbacks Object](http://api.jquery.com/category/callbacks-object/)
185-
* Callbacks.toObservable
179+
* [`ajax`](http://api.jquery.com/jQuery.ajax/) - `$.ajaxAsObservable`
180+
* [`get`](http://api.jquery.com/jQuery.get/) - `$.getAsObservable`
181+
* [`getJSON`](http://api.jquery.com/jQuery.getJSON/) - `$.getJSONAsObservable`
182+
* [`getScript`](http://api.jquery.com/jQuery.getScript/) - `$.getScriptAsObservable`
183+
* [`post`](http://api.jquery.com/jQuery.post/) - `$.postAsObservable`
184+
185+
* [`$.Deferred`](http://api.jquery.com/category/deferred-object/)
186+
* `Deferred.toObservable`
187+
* `Rx.Observable.toDeferred`
188+
189+
* [`$.Callbacks`](http://api.jquery.com/category/callbacks-object/)
190+
* `Callbacks.toObservable`
186191

187192
## LICENSE
188193

0 commit comments

Comments
 (0)