Skip to content

Commit 6cf7296

Browse files
jooyunghanjayphelps
authored andcommitted
fix(partition): handles thisArg as expected (#2138)
This fix ensures that the `partition` will call `predicate` with`thisArg` as expected if it is specified.
1 parent 9ebc46b commit 6cf7296

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

spec/operators/partition-spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ describe('Observable.prototype.partition', () => {
3939
expectSubscriptions(e1.subscriptions).toBe([e1subs, e1subs]);
4040
});
4141

42+
it('should partition an observable into two using a predicate and thisArg', () => {
43+
const e1 = hot('--a-b---a------d--a---c--|');
44+
const e1subs = '^ !';
45+
const expected = ['--a-----a---------a------|',
46+
'----b----------d------c--|'];
47+
48+
function predicate(x) {
49+
return x === this.value;
50+
}
51+
52+
expectObservableArray(e1.partition(predicate, {value: 'a'}), expected);
53+
expectSubscriptions(e1.subscriptions).toBe([e1subs, e1subs]);
54+
});
55+
4256
it('should pass errors to both returned observables', () => {
4357
const e1 = hot('--a-b---#');
4458
const e1subs = '^ !';
@@ -225,4 +239,14 @@ describe('Observable.prototype.partition', () => {
225239
const e1 = hot('--a-b---a------d----');
226240
expect(e1.partition).to.throw();
227241
});
242+
243+
it('should accept thisArg', () => {
244+
const thisArg = {};
245+
246+
Observable.of(1).partition(function (value: number) {
247+
expect(this).to.deep.equal(thisArg);
248+
return true;
249+
}, thisArg)
250+
.forEach((observable: Rx.Observable<number>) => observable.subscribe());
251+
});
228252
});

src/operator/partition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import { Observable } from '../Observable';
4545
*/
4646
export function partition<T>(this: Observable<T>, predicate: (value: T) => boolean, thisArg?: any): [Observable<T>, Observable<T>] {
4747
return [
48-
filter.call(this, predicate),
48+
filter.call(this, predicate, thisArg),
4949
filter.call(this, not(predicate, thisArg))
5050
];
5151
}

0 commit comments

Comments
 (0)