Skip to content

Commit

Permalink
feat(rxjs): remove thisArg from every operator
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `every` operator no longer supports providing `thisArg`. Use `Function#bind` or closure instead.
  • Loading branch information
benlesh committed Jan 23, 2024
1 parent 4aec7bd commit 3ca53cd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 58 deletions.
43 changes: 0 additions & 43 deletions packages/rxjs/spec/operators/every-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ describe('every', () => {
});
});

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

of(1)
.pipe(
every(function (this: any, value: number, index: number) {
expect(this).to.deep.equal(thisArg);
return true;
}, thisArg)
)
.subscribe();
});

it('should increment index on each call to the predicate', () => {
const indices: number[] = [];
of(1, 2, 3, 4)
Expand All @@ -60,36 +47,6 @@ describe('every', () => {
expect(indices).to.deep.equal([0, 1, 2, 3]);
});

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

of(1, 2, 3, 4)
.pipe(
every(function (this: any, value: number, index: number) {
expect(this).to.deep.equal(thisArg);
return true;
}, thisArg)
)
.subscribe();
});

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

const source = new Observable((observer: Observer<number>) => {
observer.next(1);
observer.complete();
});
source
.pipe(
every(function (this: any, value: number, index: number) {
expect(this).to.deep.equal(thisArg);
return true;
}, thisArg)
)
.subscribe();
});

it('should emit true if source is empty', () => {
testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => {
const e1 = hot(' -----| ');
Expand Down
17 changes: 2 additions & 15 deletions packages/rxjs/src/internal/operators/every.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ import { Observable, operate } from '../Observable.js';
import type { Falsy, OperatorFunction } from '../types.js';

export function every<T>(predicate: BooleanConstructor): OperatorFunction<T, Exclude<T, Falsy> extends never ? false : boolean>;
/** @deprecated Use a closure instead of a `thisArg`. Signatures accepting a `thisArg` will be removed in v8. */
export function every<T>(
predicate: BooleanConstructor,
thisArg: any
): OperatorFunction<T, Exclude<T, Falsy> extends never ? false : boolean>;
/** @deprecated Use a closure instead of a `thisArg`. Signatures accepting a `thisArg` will be removed in v8. */
export function every<T, A>(
predicate: (this: A, value: T, index: number, source: Observable<T>) => boolean,
thisArg: A
): OperatorFunction<T, boolean>;
export function every<T>(predicate: (value: T, index: number, source: Observable<T>) => boolean): OperatorFunction<T, boolean>;

/**
Expand Down Expand Up @@ -39,18 +29,15 @@ export function every<T>(predicate: (value: T, index: number, source: Observable
* @return A function that returns an Observable of booleans that determines if
* all items of the source Observable meet the condition specified.
*/
export function every<T>(
predicate: (value: T, index: number, source: Observable<T>) => boolean,
thisArg?: any
): OperatorFunction<T, boolean> {
export function every<T>(predicate: (value: T, index: number, source: Observable<T>) => boolean): OperatorFunction<T, boolean> {
return (source) =>
new Observable((destination) => {
let index = 0;
source.subscribe(
operate({
destination,
next: (value) => {
if (!predicate.call(thisArg, value, index++, source)) {
if (!predicate(value, index++, source)) {
destination.next(false);
destination.complete();
}
Expand Down

0 comments on commit 3ca53cd

Please sign in to comment.