From feea9a11f1d40a70b2927167f7cabcdb9ed84979 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Thu, 3 Dec 2015 13:36:02 -0800 Subject: [PATCH] feat(bindCallback): remove thisArg thisArg is removed as this method does not mirror any native function with a thisArg related #878 --- spec/observables/bindCallback-spec.js | 19 ++----------------- src/Observable.ts | 2 +- src/observable/bindCallback.ts | 11 ++++------- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/spec/observables/bindCallback-spec.js b/spec/observables/bindCallback-spec.js index e5395f4b9a..c57195303b 100644 --- a/spec/observables/bindCallback-spec.js +++ b/spec/observables/bindCallback-spec.js @@ -22,7 +22,7 @@ describe('Observable.bindCallback', function () { function callback(datum, cb) { cb(null, datum); } - var boundCallback = Observable.bindCallback(callback, null, function (err, datum) { return datum; }); + var boundCallback = Observable.bindCallback(callback, function (err, datum) { return datum; }); boundCallback(42) .subscribe(function (x) { @@ -33,26 +33,11 @@ describe('Observable.bindCallback', function () { done); }); - it('should override `this` in the callback', function (done) { - function callback(cb) { - cb(this.value); - } - var boundCallback = Observable.bindCallback(callback, {value: 42}); - - boundCallback() - .subscribe(function (x) { - expect(x).toBe(42); - }, function () { - done.fail('should not be called'); - }, - done); - }); - it('should emit an error when the selector throws', function (done) { function callback(cb) { cb(42); } - var boundCallback = Observable.bindCallback(callback, null, function (err) { throw new Error('Yikes!'); }); + var boundCallback = Observable.bindCallback(callback, function (err) { throw new Error('Yikes!'); }); boundCallback() .subscribe(function () { diff --git a/src/Observable.ts b/src/Observable.ts index 1decd4a02a..06eec0a64b 100644 --- a/src/Observable.ts +++ b/src/Observable.ts @@ -134,7 +134,7 @@ export class Observable implements CoreOperators { } // static method stubs - static bindCallback: (callbackFunc: Function, ctx?: Object, selector?: Function, scheduler?: Scheduler) => Function; + static bindCallback: (callbackFunc: Function, selector?: Function, scheduler?: Scheduler) => Function; static combineLatest: (...observables: Array | Array> | ((...values: Array) => T) | diff --git a/src/observable/bindCallback.ts b/src/observable/bindCallback.ts index bcbdbb7595..b25d41990c 100644 --- a/src/observable/bindCallback.ts +++ b/src/observable/bindCallback.ts @@ -12,16 +12,14 @@ export class BoundCallbackObservable extends Observable { value: T | T[]; static create(callbackFunc: Function, - ctx: Object = undefined, selector: Function = undefined, scheduler: Scheduler = immediate): Function { return (...args): Observable => { - return new BoundCallbackObservable(callbackFunc, ctx, selector, args, scheduler); + return new BoundCallbackObservable(callbackFunc, selector, args, scheduler); }; } constructor(private callbackFunc: Function, - private ctx, private selector, private args: any[], public scheduler: Scheduler = immediate) { @@ -30,7 +28,6 @@ export class BoundCallbackObservable extends Observable { _subscribe(subscriber: Subscriber) { const callbackFunc = this.callbackFunc; - const ctx = this.ctx; const selector = this.selector; const args = this.args; const scheduler = this.scheduler; @@ -49,7 +46,7 @@ export class BoundCallbackObservable extends Observable { this.value = innerArgs; if (selector) { - results = tryCatch(selector).apply(ctx, innerArgs); + results = tryCatch(selector).apply(this, innerArgs); if (results === errorObject) { return subscriber.error(results.e); } subscriber.next(results); } else { @@ -74,7 +71,7 @@ export class BoundCallbackObservable extends Observable { this._isScalar = true; if (selector) { - results = tryCatch(selector).apply(ctx, innerArgs); + results = tryCatch(selector).apply(this, innerArgs); if (results === errorObject) { return subscription.add(scheduler.schedule(dispatchError, 0, { err: results.e, subscriber })); } @@ -95,7 +92,7 @@ export class BoundCallbackObservable extends Observable { if (handler) { args.push(handler); - callbackFunc.apply(ctx, args); + callbackFunc.apply(this, args); } } }