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

Commit b04b562

Browse files
Updating to use publish/refcount for events
1 parent f535bda commit b04b562

File tree

13 files changed

+742
-742
lines changed

13 files changed

+742
-742
lines changed

Gruntfile.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ module.exports = function (grunt) {
2727
'src/license.js',
2828
'src/intro.js',
2929
'src/basicheader.js',
30-
'src/rx-jquery.js',
30+
'src/deferred.js',
31+
'src/callbacks.js',
32+
'src/events.js',
33+
'src/animation.js',
34+
'src/ajax.js',
3135
'src/outro.js'
3236
],
3337
dest: 'rx.jquery.js'

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.2",
3+
"version": "1.1.3",
44
"main": "rx.jquery.js",
55
"dependencies": {
66
"rxjs": "*"

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

Lines changed: 3 additions & 2 deletions
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.2</version>
7+
<version>1.1.3</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>
@@ -15,7 +15,8 @@
1515
<tags>Rx RxJS Reactive Extensions Observable</tags>
1616
<dependencies>
1717
<!-- Automatically updated by build, keeping fixed dev build number here in case of local build -->
18-
<dependency id="RxJS-Main" version="2.1.15" />
18+
<dependency id="RxJS-Main" version="2.1" />
19+
<dependency id="RxJS-Binding" version="2.1" />
1920
<dependency id="jQuery" />
2021
</dependencies>
2122
</metadata>

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.2",
5+
"version": "1.1.3",
66
"homepage": "https://github.com/Reactive-Extensions/rxjs-jquery",
77
"author": {
88
"name": "MS Open Tech",

rx.jquery.js

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,29 @@
5555
return deferred;
5656
};
5757
}
58-
59-
60-
//in order to support jQuery 1.6.*
58+
//in order to support jQuery 1.6.*
6159
if ($.Callbacks) {
6260

6361
/**
6462
* Converts an existing Callbacks object to an Observable sequence
6563
* @returns {Observable} An Observable sequence created from a jQuery Callbacks object.
6664
*/
6765
$.Callbacks.prototype.toObservable = function () {
68-
var parent = this;
69-
return observableCreate(function (observer) {
70-
71-
function handler(values) {
72-
observer.onNext(values);
73-
}
66+
var parent = this;
67+
return observableCreate(function (observer) {
7468

75-
parent.add(handler);
69+
function handler(values) {
70+
observer.onNext(values);
71+
}
7672

77-
return function () {
78-
parent.remove(handler);
79-
};
80-
});
81-
};
82-
}
73+
parent.add(handler);
8374

84-
if (!!proto.on) {
75+
return function () {
76+
parent.remove(handler);
77+
};
78+
});
79+
};
80+
} if (!!proto.on) {
8581
/**
8682
* Attach an event handler function for one or more events to the selected elements as an Observable sequence.
8783
*
@@ -106,7 +102,7 @@
106102
return function() {
107103
parent.off.apply(parent, args);
108104
};
109-
});
105+
}).publish().refCount();
110106
};
111107
}
112108

@@ -131,7 +127,7 @@
131127
return function() {
132128
parent.unbind(eventType, eventData, handler);
133129
};
134-
});
130+
}).publish().refCount();
135131
};
136132

137133
/**
@@ -156,7 +152,7 @@
156152
return function() {
157153
parent.undelegate(selector, eventType, handler);
158154
};
159-
});
155+
}).publish().refCount();
160156
};
161157

162158
// Removed as of 1.9
@@ -182,7 +178,7 @@
182178
return function() {
183179
parent.die(eventType, data, handler);
184180
};
185-
});
181+
}).publish().refCount();
186182
};
187183
}
188184

@@ -434,7 +430,6 @@
434430
parent.ready(handler);
435431
});
436432
};
437-
438433
function handeAnimation(jQueryProto, method, args) {
439434
var options = args[0];
440435

@@ -672,7 +667,6 @@
672667
proto.toggleAsObservable = function(duration, easing) {
673668
return handeAnimation(this, 'toggle', arguments);
674669
};
675-
676670
var ajaxAsObservable = $.ajaxAsObservable = function(settings) {
677671
var subject = new AsyncSubject();
678672

rx.jquery.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ajax.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
var ajaxAsObservable = $.ajaxAsObservable = function(settings) {
3+
var subject = new AsyncSubject();
4+
5+
var internalSettings = {
6+
success: function(data, textStatus, jqXHR) {
7+
subject.onNext({ data: data, textStatus: textStatus, jqXHR: jqXHR });
8+
subject.onCompleted();
9+
},
10+
error: function(jqXHR, textStatus, errorThrown) {
11+
subject.onError({ jqXHR: jqXHR, textStatus: textStatus, errorThrown: errorThrown });
12+
}
13+
};
14+
15+
$.extend(true, internalSettings, settings);
16+
17+
$.ajax(internalSettings);
18+
19+
return subject;
20+
};
21+
22+
/**
23+
* Load data from the server using a HTTP GET request as an Observable sequence.
24+
*
25+
* @param {String} url A string containing the URL to which the request is sent.
26+
* @param {Object} [data] A plain object or string that is sent to the server with the request.
27+
* @param {String} [dataType] The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).
28+
* @returns {Observable} An Observable sequence which wraps the jQuery get method.
29+
*/
30+
$.getAsObservable = function(url, data, dataType) {
31+
return ajaxAsObservable({ url: url, dataType: dataType, data: data });
32+
};
33+
34+
/**
35+
* Load JSON-encoded data from the server using a GET HTTP request as an Observable sequence.
36+
*
37+
* @param {String} url A string containing the URL to which the request is sent.
38+
* @param {Object} [data] A plain object or string that is sent to the server with the request.
39+
* @returns {Observable} An Observable sequence which wraps the jQuery getJSON method.
40+
*/
41+
$.getJSONAsObservable = function(url, data) {
42+
return ajaxAsObservable({ url: url, dataType: 'json', data: data });
43+
};
44+
45+
/**
46+
* Load a JavaScript file from the server using a GET HTTP request, then execute it as an Observable sequence.
47+
*
48+
* @param {String} url A string containing the URL to which the request is sent.
49+
* @returns {Observable} An Observable sequence which wraps the jQuery getJSON method.
50+
*/
51+
$.getScriptAsObservable = function(url) {
52+
return ajaxAsObservable({ url: url, dataType: 'script'});
53+
};
54+
55+
/**
56+
* Load data from the server using a HTTP POST request as an Observable sequence.
57+
*
58+
* @param {String} url A string containing the URL to which the request is sent.
59+
* @param {Object} [data] A plain object or string that is sent to the server with the request.
60+
* @param {String} [dataType] The type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).
61+
* @returns {Observable} An Observable sequence which wraps the jQuery get method.
62+
*/
63+
$.postAsObservable = function(url, data, dataType) {
64+
return ajaxAsObservable({ url: url, dataType: dataType, data: data, type: 'POST'});
65+
};

0 commit comments

Comments
 (0)