Skip to content

Commit

Permalink
chore(delayWhen): Revert "feat(delayWhen): add index to the selector …
Browse files Browse the repository at this point in the history
…function" (#2472)
  • Loading branch information
kwonoj authored and benlesh committed Mar 16, 2017
1 parent a88ac2a commit e2696db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
19 changes: 0 additions & 19 deletions spec/operators/delayWhen-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {expect} from 'chai';
import * as Rx from '../../dist/cjs/Rx';
import marbleTestingSignature = require('../helpers/marble-testing'); // tslint:disable-line:no-require-imports

Expand Down Expand Up @@ -216,22 +215,4 @@ describe('Observable.prototype.delayWhen', () => {
expectSubscriptions(selector.subscriptions).toBe([]);
expectSubscriptions(subDelay.subscriptions).toBe(subDelaySub);
});

it('should call predicate with indices starting at 0', () => {
const e1 = hot('--a--b--c--|');
const expected = '--a--b--c--|';
const selector = cold('(x|)');

let indices = [];
const predicate = (value, index) => {
indices.push(index);
return selector;
};

const result = e1.delayWhen(predicate);

expectObservable(result.do(null, null, () => {
expect(indices).to.deep.equal([0, 1, 2]);
})).toBe(expected);
});
});
12 changes: 5 additions & 7 deletions src/operator/delayWhen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { subscribeToResult } from '../util/subscribeToResult';
* @see {@link debounce}
* @see {@link delay}
*
* @param {function(value: T, index: number): Observable} delayDurationSelector A function that
* @param {function(value: T): Observable} delayDurationSelector A function that
* returns an Observable for each value emitted by the source Observable, which
* is then used to delay the emission of that item on the output Observable
* until the Observable returned from this function emits a value.
Expand All @@ -52,7 +52,7 @@ import { subscribeToResult } from '../util/subscribeToResult';
* @method delayWhen
* @owner Observable
*/
export function delayWhen<T>(this: Observable<T>, delayDurationSelector: (value: T, index: number) => Observable<any>,
export function delayWhen<T>(this: Observable<T>, delayDurationSelector: (value: T) => Observable<any>,
subscriptionDelay?: Observable<any>): Observable<T> {
if (subscriptionDelay) {
return new SubscriptionDelayObservable(this, subscriptionDelay)
Expand All @@ -62,7 +62,7 @@ export function delayWhen<T>(this: Observable<T>, delayDurationSelector: (value:
}

class DelayWhenOperator<T> implements Operator<T, T> {
constructor(private delayDurationSelector: (value: T, index: number) => Observable<any>) {
constructor(private delayDurationSelector: (value: T) => Observable<any>) {
}

call(subscriber: Subscriber<T>, source: any): TeardownLogic {
Expand All @@ -79,10 +79,9 @@ class DelayWhenSubscriber<T, R> extends OuterSubscriber<T, R> {
private completed: boolean = false;
private delayNotifierSubscriptions: Array<Subscription> = [];
private values: Array<T> = [];
private index: number = 0;

constructor(destination: Subscriber<T>,
private delayDurationSelector: (value: T, index: number) => Observable<any>) {
private delayDurationSelector: (value: T) => Observable<any>) {
super(destination);
}

Expand All @@ -107,9 +106,8 @@ class DelayWhenSubscriber<T, R> extends OuterSubscriber<T, R> {
}

protected _next(value: T): void {
const index = this.index++;
try {
const delayNotifier = this.delayDurationSelector(value, index);
const delayNotifier = this.delayDurationSelector(value);
if (delayNotifier) {
this.tryDelay(delayNotifier, value);
}
Expand Down

0 comments on commit e2696db

Please sign in to comment.