Skip to content

Commit

Permalink
perf(filter): add fast-path for filtering scalar observables
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Oct 14, 2015
1 parent e80bab6 commit e2e8954
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/observables/ScalarObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,15 @@ export default class ScalarObservable<T> extends Observable<T> {
return new ScalarObservable(project.call(thisArg || this, this.value, 0));
}
}

filter(select: (x: T, ix?: number) => boolean, thisArg?: any): Observable<T> {
let result = tryCatch(select).call(thisArg || this, this.value, 0);
if (result === errorObject) {
return new ErrorObservable(errorObject.e);
} else if (result) {
return this;
} else {
return new EmptyObservable();
}
}
}

0 comments on commit e2e8954

Please sign in to comment.