Skip to content

Commit

Permalink
feat(single): remove thisArg
Browse files Browse the repository at this point in the history
Relates to #878.
  • Loading branch information
luisgabriel authored and benlesh committed Dec 8, 2015
1 parent 3c27b4c commit 43af805
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/CoreOperators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export interface CoreOperators<T> {
sampleTime?: (delay: number, scheduler?: Scheduler) => Observable<T>;
scan?: <R>(project: (acc: R, x: T) => R, acc?: R) => Observable<R>;
share?: () => Observable<T>;
single?: (predicate?: (value: T, index: number) => boolean, thisArg?: any) => Observable<T>;
single?: (predicate?: (value: T, index: number) => boolean) => Observable<T>;
skip?: (count: number) => Observable<T>;
skipUntil?: (notifier: Observable<any>) => Observable<T>;
skipWhile?: (predicate: (x: T, index: number) => boolean, thisArg?: any) => Observable<T>;
Expand Down
2 changes: 1 addition & 1 deletion src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class Observable<T> implements CoreOperators<T> {
sampleTime: (delay: number, scheduler?: Scheduler) => Observable<T>;
scan: <R>(accumulator: (acc: R, x: T) => R, seed?: T | R) => Observable<R>;
share: () => Observable<T>;
single: (predicate?: (value: T, index: number) => boolean, thisArg?: any) => Observable<T>;
single: (predicate?: (value: T, index: number) => boolean) => Observable<T>;
skip: (count: number) => Observable<T>;
skipUntil: (notifier: Observable<any>) => Observable<T>;
skipWhile: (predicate: (x: T, index: number) => boolean, thisArg?: any) => Observable<T>;
Expand Down
17 changes: 4 additions & 13 deletions src/operator/single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,33 @@ import {Observer} from '../Observer';

import {tryCatch} from '../util/tryCatch';
import {errorObject} from '../util/errorObject';
import {bindCallback} from '../util/bindCallback';
import {EmptyError} from '../util/EmptyError';

export function single<T>(predicate?: (value: T,
index: number,
source: Observable<T>) => boolean,
thisArg?: any): Observable<T> {
return this.lift(new SingleOperator(predicate, thisArg, this));
source: Observable<T>) => boolean): Observable<T> {
return this.lift(new SingleOperator(predicate, this));
}

class SingleOperator<T, R> implements Operator<T, R> {
constructor(private predicate?: (value: T, index: number, source: Observable<T>) => boolean,
private thisArg?: any,
private source?: Observable<T>) {
}

call(subscriber: Subscriber<T>): Subscriber<T> {
return new SingleSubscriber(subscriber, this.predicate, this.thisArg, this.source);
return new SingleSubscriber(subscriber, this.predicate, this.source);
}
}

class SingleSubscriber<T> extends Subscriber<T> {
private predicate: Function;
private seenValue: boolean = false;
private singleValue: T;
private index: number = 0;

constructor(destination: Observer<T>,
predicate?: (value: T, index: number, source: Observable<T>) => boolean,
private thisArg?: any,
private predicate?: (value: T, index: number, source: Observable<T>) => boolean,
private source?: Observable<T>) {
super(destination);

if (typeof predicate === 'function') {
this.predicate = bindCallback(predicate, thisArg, 3);
}
}

private applySingleValue(value): void {
Expand Down

0 comments on commit 43af805

Please sign in to comment.