Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(partition): handles thisArg as expected #2138

Merged
merged 1 commit into from Nov 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions spec/operators/partition-spec.ts
Expand Up @@ -39,6 +39,20 @@ describe('Observable.prototype.partition', () => {
expectSubscriptions(e1.subscriptions).toBe([e1subs, e1subs]);
});

it('should partition an observable into two using a predicate and thisArg', () => {
const e1 = hot('--a-b---a------d--a---c--|');
const e1subs = '^ !';
const expected = ['--a-----a---------a------|',
'----b----------d------c--|'];

function predicate(x) {
return x === this.value;
}

expectObservableArray(e1.partition(predicate, {value: 'a'}), expected);
expectSubscriptions(e1.subscriptions).toBe([e1subs, e1subs]);
});

it('should pass errors to both returned observables', () => {
const e1 = hot('--a-b---#');
const e1subs = '^ !';
Expand Down Expand Up @@ -225,4 +239,14 @@ describe('Observable.prototype.partition', () => {
const e1 = hot('--a-b---a------d----');
expect(e1.partition).to.throw();
});

it('should accept thisArg', () => {
const thisArg = {};

Observable.of(1).partition(function (value: number) {
expect(this).to.deep.equal(thisArg);
return true;
}, thisArg)
.forEach((observable: Rx.Observable<number>) => observable.subscribe());
});
});
2 changes: 1 addition & 1 deletion src/operator/partition.ts
Expand Up @@ -45,7 +45,7 @@ import { Observable } from '../Observable';
*/
export function partition<T>(this: Observable<T>, predicate: (value: T) => boolean, thisArg?: any): [Observable<T>, Observable<T>] {
return [
filter.call(this, predicate),
filter.call(this, predicate, thisArg),
filter.call(this, not(predicate, thisArg))
];
}