Skip to content

Commit

Permalink
fix(Observable.prototype.forEach): removed thisArg to match es-observ…
Browse files Browse the repository at this point in the history
…able spec

BREAKING CHANGE: thisArg removed to match es-observable spec
  • Loading branch information
tetsuharuohzeki authored and kwonoj committed Mar 3, 2016
1 parent 6c76593 commit d5f1bcd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
16 changes: 2 additions & 14 deletions spec/Observable-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Observable', () => {
const expected = [1, 2, 3];
const result = Observable.of(1, 2, 3).forEach(function (x) {
expect(x).toBe(expected.shift());
}, null, Promise)
}, Promise)
.then(done);

expect(typeof result.then).toBe('function');
Expand All @@ -39,7 +39,7 @@ describe('Observable', () => {
it('should reject promise when in error', (done: DoneSignature) => {
Observable.throw('bad').forEach((x: any) => {
done.fail('should not be called');
}, null, Promise).then(() => {
}, Promise).then(() => {
done.fail('should not complete');
}, (err: any) => {
expect(err).toBe('bad');
Expand All @@ -65,18 +65,6 @@ describe('Observable', () => {
});
});

it('should accept a thisArg argument', (done: DoneSignature) => {
const expected = [1, 2, 3];
const thisArg = {};
const result = Observable.of(1, 2, 3).forEach(function (x) {
expect(this).toBe(thisArg);
expect(x).toBe(expected.shift());
}, thisArg, Promise)
.then(done);

expect(typeof result.then).toBe('function');
});

it('should reject promise if nextHandler throws', (done: DoneSignature) => {
const results = [];
Observable.of(1, 2, 3).forEach((x: number) => {
Expand Down
5 changes: 2 additions & 3 deletions src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,11 @@ export class Observable<T> implements CoreOperators<T> {
/**
* @method forEach
* @param {Function} next a handler for each value emitted by the observable
* @param {any} [thisArg] a `this` context for the `next` handler function
* @param {PromiseConstructor} [PromiseCtor] a constructor function used to instantiate the Promise
* @return {Promise} a promise that either resolves on observable completion or
* rejects with the handled error
*/
forEach(next: (value: T) => void, thisArg: any, PromiseCtor?: typeof Promise): Promise<void> {
forEach(next: (value: T) => void, PromiseCtor?: typeof Promise): Promise<void> {
if (!PromiseCtor) {
if (root.Rx && root.Rx.config && root.Rx.config.Promise) {
PromiseCtor = root.Rx.config.Promise;
Expand All @@ -235,7 +234,7 @@ export class Observable<T> implements CoreOperators<T> {

return new PromiseCtor<void>((resolve, reject) => {
source.subscribe((value: T) => {
const result: any = tryCatch(next).call(thisArg, value);
const result: any = tryCatch(next)(value);
if (result === errorObject) {
reject(errorObject.e);
}
Expand Down

0 comments on commit d5f1bcd

Please sign in to comment.