Skip to content

Commit

Permalink
Revert "fix(elementAt): will now properly unsubscribe when it complet…
Browse files Browse the repository at this point in the history
…es or errors (#2501)" (#2664)

This reverts commit a400cab.
  • Loading branch information
benlesh authored Jun 14, 2017
1 parent ccc0647 commit 97ce813
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 50 deletions.
16 changes: 0 additions & 16 deletions spec/helpers/doNotUnsubscribe.ts

This file was deleted.

30 changes: 0 additions & 30 deletions spec/operators/elementAt-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {expect} from 'chai';
import * as Rx from '../../dist/cjs/Rx';
import marbleTestingSignature = require('../helpers/marble-testing'); // tslint:disable-line:no-require-imports
import { doNotUnsubscribe } from '../helpers/doNotUnsubscribe';

declare const { asDiagram };
declare const hot: typeof marbleTestingSignature.hot;
Expand Down Expand Up @@ -127,33 +126,4 @@ describe('Observable.prototype.elementAt', () => {
expectObservable((<any>source).elementAt(3, defaultValue)).toBe(expected, { x: defaultValue });
expectSubscriptions(source.subscriptions).toBe(subs);
});

it('should unsubscribe from source Observable, even if destination does not unsubscribe', () => {
const source = hot('--a--b--c-d---|');
const subs = '^ ! ';
const expected = '--------(c|) ';

expectObservable((<any>source).elementAt(2).let(doNotUnsubscribe)).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

it('should unsubscribe from source if index is out of range, even if destination does not unsubscribe', () => {
const source = hot('--a--|');
const subs = '^ !';
const expected = '-----#';

expectObservable((<any>source).elementAt(3).let(doNotUnsubscribe))
.toBe(expected, null, new Rx.ArgumentOutOfRangeError());
expectSubscriptions(source.subscriptions).toBe(subs);
});

it('should unsubscribe when returning default value, even if destination does not unsubscribe', () => {
const source = hot('--a--|');
const subs = '^ !';
const expected = '-----(x|)';
const defaultValue = '42';

expectObservable((<any>source).elementAt(3, defaultValue).let(doNotUnsubscribe)).toBe(expected, { x: defaultValue });
expectSubscriptions(source.subscriptions).toBe(subs);
});
});
4 changes: 0 additions & 4 deletions src/operator/elementAt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class ElementAtSubscriber<T> extends Subscriber<T> {
if (this.index-- === 0) {
this.destination.next(x);
this.destination.complete();
this.unsubscribe();
}
}

Expand All @@ -89,11 +88,8 @@ class ElementAtSubscriber<T> extends Subscriber<T> {
destination.next(this.defaultValue);
} else {
destination.error(new ArgumentOutOfRangeError);
this.unsubscribe();
return;
}
}
destination.complete();
this.unsubscribe();
}
}

0 comments on commit 97ce813

Please sign in to comment.