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

Commit 33fcd25

Browse files
Fixing AnonymousObservable for perf for Issue #519
1 parent 02bbbbb commit 33fcd25

20 files changed

Lines changed: 221 additions & 208 deletions

dist/rx.all.compat.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,7 @@
23222322
* @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
23232323
*/
23242324
observableProto.subscribeOnNext = function (onNext, thisArg) {
2325-
return this._subscribe(observerCreate(arguments.length === 2 ? function(x) { onNext.call(thisArg, x); } : onNext));
2325+
return this._subscribe(observerCreate(typeof thisArg !== 'undefined' ? function(x) { onNext.call(thisArg, x); } : onNext));
23262326
};
23272327

23282328
/**
@@ -2332,7 +2332,7 @@
23322332
* @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
23332333
*/
23342334
observableProto.subscribeOnError = function (onError, thisArg) {
2335-
return this._subscribe(observerCreate(null, arguments.length === 2 ? function(e) { onError.call(thisArg, e); } : onError));
2335+
return this._subscribe(observerCreate(null, typeof thisArg !== 'undefined' ? function(e) { onError.call(thisArg, e); } : onError));
23362336
};
23372337

23382338
/**
@@ -2342,7 +2342,7 @@
23422342
* @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
23432343
*/
23442344
observableProto.subscribeOnCompleted = function (onCompleted, thisArg) {
2345-
return this._subscribe(observerCreate(null, null, arguments.length === 2 ? function() { onCompleted.call(thisArg); } : onCompleted));
2345+
return this._subscribe(observerCreate(null, null, typeof thisArg !== 'undefined' ? function() { onCompleted.call(thisArg); } : onCompleted));
23462346
};
23472347

23482348
return Observable;
@@ -9713,36 +9713,38 @@
97139713
disposableEmpty;
97149714
}
97159715

9716-
function AnonymousObservable(subscribe, parent) {
9717-
this.source = parent;
9718-
if (!(this instanceof AnonymousObservable)) {
9719-
return new AnonymousObservable(subscribe);
9716+
function subscribe(observer) {
9717+
var self = this;
9718+
var ado = new AutoDetachObserver(observer);
9719+
if (currentThreadScheduler.scheduleRequired()) {
9720+
currentThreadScheduler.scheduleWithState(ado, function (x, ado) { return self.scheduledSubscribe(x, ado); })
9721+
} else {
9722+
try {
9723+
ado.setDisposable(fixSubscriber(this.subscribeCore(ado)));
9724+
} catch (e) {
9725+
if (!ado.fail(e)) { throw e; }
9726+
}
97209727
}
97219728

9722-
function s(observer) {
9723-
var setDisposable = function () {
9724-
try {
9725-
autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
9726-
} catch (e) {
9727-
if (!autoDetachObserver.fail(e)) {
9728-
throw e;
9729-
}
9730-
}
9731-
};
9732-
9733-
var autoDetachObserver = new AutoDetachObserver(observer);
9734-
if (currentThreadScheduler.scheduleRequired()) {
9735-
currentThreadScheduler.schedule(setDisposable);
9736-
} else {
9737-
setDisposable();
9738-
}
9729+
return ado;
9730+
}
97399731

9740-
return autoDetachObserver;
9741-
}
9732+
function AnonymousObservable(subscribeMethod, parent) {
9733+
this.source = parent;
9734+
this.subscribeCore = subscribeMethod;
97429735

9743-
__super__.call(this, s);
9736+
__super__.call(this, subscribe);
97449737
}
97459738

9739+
AnonymousObservable.prototype.scheduledSubscribe = function (x, ado) {
9740+
try {
9741+
ado.setDisposable(fixSubscriber(this.subscribeCore(ado)));
9742+
} catch (e) {
9743+
if (!ado.fail(e)) { throw e; }
9744+
}
9745+
return disposableEmpty;
9746+
};
9747+
97469748
return AnonymousObservable;
97479749

97489750
}(Observable));

dist/rx.all.compat.map

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

dist/rx.all.compat.min.js

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

dist/rx.all.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,7 +2133,7 @@
21332133
* @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
21342134
*/
21352135
observableProto.subscribeOnNext = function (onNext, thisArg) {
2136-
return this._subscribe(observerCreate(arguments.length === 2 ? function(x) { onNext.call(thisArg, x); } : onNext));
2136+
return this._subscribe(observerCreate(typeof thisArg !== 'undefined' ? function(x) { onNext.call(thisArg, x); } : onNext));
21372137
};
21382138

21392139
/**
@@ -2143,7 +2143,7 @@
21432143
* @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
21442144
*/
21452145
observableProto.subscribeOnError = function (onError, thisArg) {
2146-
return this._subscribe(observerCreate(null, arguments.length === 2 ? function(e) { onError.call(thisArg, e); } : onError));
2146+
return this._subscribe(observerCreate(null, typeof thisArg !== 'undefined' ? function(e) { onError.call(thisArg, e); } : onError));
21472147
};
21482148

21492149
/**
@@ -2153,7 +2153,7 @@
21532153
* @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
21542154
*/
21552155
observableProto.subscribeOnCompleted = function (onCompleted, thisArg) {
2156-
return this._subscribe(observerCreate(null, null, arguments.length === 2 ? function() { onCompleted.call(thisArg); } : onCompleted));
2156+
return this._subscribe(observerCreate(null, null, typeof thisArg !== 'undefined' ? function() { onCompleted.call(thisArg); } : onCompleted));
21572157
};
21582158

21592159
return Observable;
@@ -9456,36 +9456,38 @@
94569456
disposableEmpty;
94579457
}
94589458

9459-
function AnonymousObservable(subscribe, parent) {
9460-
this.source = parent;
9461-
if (!(this instanceof AnonymousObservable)) {
9462-
return new AnonymousObservable(subscribe);
9459+
function subscribe(observer) {
9460+
var self = this;
9461+
var ado = new AutoDetachObserver(observer);
9462+
if (currentThreadScheduler.scheduleRequired()) {
9463+
currentThreadScheduler.scheduleWithState(ado, function (x, ado) { return self.scheduledSubscribe(x, ado); })
9464+
} else {
9465+
try {
9466+
ado.setDisposable(fixSubscriber(this.subscribeCore(ado)));
9467+
} catch (e) {
9468+
if (!ado.fail(e)) { throw e; }
9469+
}
94639470
}
94649471

9465-
function s(observer) {
9466-
var setDisposable = function () {
9467-
try {
9468-
autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
9469-
} catch (e) {
9470-
if (!autoDetachObserver.fail(e)) {
9471-
throw e;
9472-
}
9473-
}
9474-
};
9475-
9476-
var autoDetachObserver = new AutoDetachObserver(observer);
9477-
if (currentThreadScheduler.scheduleRequired()) {
9478-
currentThreadScheduler.schedule(setDisposable);
9479-
} else {
9480-
setDisposable();
9481-
}
9472+
return ado;
9473+
}
94829474

9483-
return autoDetachObserver;
9484-
}
9475+
function AnonymousObservable(subscribeMethod, parent) {
9476+
this.source = parent;
9477+
this.subscribeCore = subscribeMethod;
94859478

9486-
__super__.call(this, s);
9479+
__super__.call(this, subscribe);
94879480
}
94889481

9482+
AnonymousObservable.prototype.scheduledSubscribe = function (x, ado) {
9483+
try {
9484+
ado.setDisposable(fixSubscriber(this.subscribeCore(ado)));
9485+
} catch (e) {
9486+
if (!ado.fail(e)) { throw e; }
9487+
}
9488+
return disposableEmpty;
9489+
};
9490+
94899491
return AnonymousObservable;
94909492

94919493
}(Observable));

dist/rx.all.map

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

dist/rx.all.min.js

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

dist/rx.compat.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,7 @@
23222322
* @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
23232323
*/
23242324
observableProto.subscribeOnNext = function (onNext, thisArg) {
2325-
return this._subscribe(observerCreate(arguments.length === 2 ? function(x) { onNext.call(thisArg, x); } : onNext));
2325+
return this._subscribe(observerCreate(typeof thisArg !== 'undefined' ? function(x) { onNext.call(thisArg, x); } : onNext));
23262326
};
23272327

23282328
/**
@@ -2332,7 +2332,7 @@
23322332
* @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
23332333
*/
23342334
observableProto.subscribeOnError = function (onError, thisArg) {
2335-
return this._subscribe(observerCreate(null, arguments.length === 2 ? function(e) { onError.call(thisArg, e); } : onError));
2335+
return this._subscribe(observerCreate(null, typeof thisArg !== 'undefined' ? function(e) { onError.call(thisArg, e); } : onError));
23362336
};
23372337

23382338
/**
@@ -2342,7 +2342,7 @@
23422342
* @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
23432343
*/
23442344
observableProto.subscribeOnCompleted = function (onCompleted, thisArg) {
2345-
return this._subscribe(observerCreate(null, null, arguments.length === 2 ? function() { onCompleted.call(thisArg); } : onCompleted));
2345+
return this._subscribe(observerCreate(null, null, typeof thisArg !== 'undefined' ? function() { onCompleted.call(thisArg); } : onCompleted));
23462346
};
23472347

23482348
return Observable;
@@ -4705,36 +4705,38 @@
47054705
disposableEmpty;
47064706
}
47074707

4708-
function AnonymousObservable(subscribe, parent) {
4709-
this.source = parent;
4710-
if (!(this instanceof AnonymousObservable)) {
4711-
return new AnonymousObservable(subscribe);
4708+
function subscribe(observer) {
4709+
var self = this;
4710+
var ado = new AutoDetachObserver(observer);
4711+
if (currentThreadScheduler.scheduleRequired()) {
4712+
currentThreadScheduler.scheduleWithState(ado, function (x, ado) { return self.scheduledSubscribe(x, ado); })
4713+
} else {
4714+
try {
4715+
ado.setDisposable(fixSubscriber(this.subscribeCore(ado)));
4716+
} catch (e) {
4717+
if (!ado.fail(e)) { throw e; }
4718+
}
47124719
}
47134720

4714-
function s(observer) {
4715-
var setDisposable = function () {
4716-
try {
4717-
autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
4718-
} catch (e) {
4719-
if (!autoDetachObserver.fail(e)) {
4720-
throw e;
4721-
}
4722-
}
4723-
};
4724-
4725-
var autoDetachObserver = new AutoDetachObserver(observer);
4726-
if (currentThreadScheduler.scheduleRequired()) {
4727-
currentThreadScheduler.schedule(setDisposable);
4728-
} else {
4729-
setDisposable();
4730-
}
4721+
return ado;
4722+
}
47314723

4732-
return autoDetachObserver;
4733-
}
4724+
function AnonymousObservable(subscribeMethod, parent) {
4725+
this.source = parent;
4726+
this.subscribeCore = subscribeMethod;
47344727

4735-
__super__.call(this, s);
4728+
__super__.call(this, subscribe);
47364729
}
47374730

4731+
AnonymousObservable.prototype.scheduledSubscribe = function (x, ado) {
4732+
try {
4733+
ado.setDisposable(fixSubscriber(this.subscribeCore(ado)));
4734+
} catch (e) {
4735+
if (!ado.fail(e)) { throw e; }
4736+
}
4737+
return disposableEmpty;
4738+
};
4739+
47384740
return AnonymousObservable;
47394741

47404742
}(Observable));

dist/rx.compat.map

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

dist/rx.compat.min.js

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

dist/rx.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,7 +2133,7 @@
21332133
* @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
21342134
*/
21352135
observableProto.subscribeOnNext = function (onNext, thisArg) {
2136-
return this._subscribe(observerCreate(arguments.length === 2 ? function(x) { onNext.call(thisArg, x); } : onNext));
2136+
return this._subscribe(observerCreate(typeof thisArg !== 'undefined' ? function(x) { onNext.call(thisArg, x); } : onNext));
21372137
};
21382138

21392139
/**
@@ -2143,7 +2143,7 @@
21432143
* @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
21442144
*/
21452145
observableProto.subscribeOnError = function (onError, thisArg) {
2146-
return this._subscribe(observerCreate(null, arguments.length === 2 ? function(e) { onError.call(thisArg, e); } : onError));
2146+
return this._subscribe(observerCreate(null, typeof thisArg !== 'undefined' ? function(e) { onError.call(thisArg, e); } : onError));
21472147
};
21482148

21492149
/**
@@ -2153,7 +2153,7 @@
21532153
* @returns {Disposable} A disposable handling the subscriptions and unsubscriptions.
21542154
*/
21552155
observableProto.subscribeOnCompleted = function (onCompleted, thisArg) {
2156-
return this._subscribe(observerCreate(null, null, arguments.length === 2 ? function() { onCompleted.call(thisArg); } : onCompleted));
2156+
return this._subscribe(observerCreate(null, null, typeof thisArg !== 'undefined' ? function() { onCompleted.call(thisArg); } : onCompleted));
21572157
};
21582158

21592159
return Observable;
@@ -4516,36 +4516,38 @@
45164516
disposableEmpty;
45174517
}
45184518

4519-
function AnonymousObservable(subscribe, parent) {
4520-
this.source = parent;
4521-
if (!(this instanceof AnonymousObservable)) {
4522-
return new AnonymousObservable(subscribe);
4519+
function subscribe(observer) {
4520+
var self = this;
4521+
var ado = new AutoDetachObserver(observer);
4522+
if (currentThreadScheduler.scheduleRequired()) {
4523+
currentThreadScheduler.scheduleWithState(ado, function (x, ado) { return self.scheduledSubscribe(x, ado); })
4524+
} else {
4525+
try {
4526+
ado.setDisposable(fixSubscriber(this.subscribeCore(ado)));
4527+
} catch (e) {
4528+
if (!ado.fail(e)) { throw e; }
4529+
}
45234530
}
45244531

4525-
function s(observer) {
4526-
var setDisposable = function () {
4527-
try {
4528-
autoDetachObserver.setDisposable(fixSubscriber(subscribe(autoDetachObserver)));
4529-
} catch (e) {
4530-
if (!autoDetachObserver.fail(e)) {
4531-
throw e;
4532-
}
4533-
}
4534-
};
4535-
4536-
var autoDetachObserver = new AutoDetachObserver(observer);
4537-
if (currentThreadScheduler.scheduleRequired()) {
4538-
currentThreadScheduler.schedule(setDisposable);
4539-
} else {
4540-
setDisposable();
4541-
}
4532+
return ado;
4533+
}
45424534

4543-
return autoDetachObserver;
4544-
}
4535+
function AnonymousObservable(subscribeMethod, parent) {
4536+
this.source = parent;
4537+
this.subscribeCore = subscribeMethod;
45454538

4546-
__super__.call(this, s);
4539+
__super__.call(this, subscribe);
45474540
}
45484541

4542+
AnonymousObservable.prototype.scheduledSubscribe = function (x, ado) {
4543+
try {
4544+
ado.setDisposable(fixSubscriber(this.subscribeCore(ado)));
4545+
} catch (e) {
4546+
if (!ado.fail(e)) { throw e; }
4547+
}
4548+
return disposableEmpty;
4549+
};
4550+
45494551
return AnonymousObservable;
45504552

45514553
}(Observable));

0 commit comments

Comments
 (0)