Skip to content

Commit d7eab2b

Browse files
authored
feat(map): removed deprecated map(project, thisArg) call pattern (#7158)
* feat(map): removed deprecated map(project, thisArg) call pattern BREAKING CHANGE: `map(project, thisArg)` call pattern is no longer available. Use Function#bind method: `map(project.bind(thisArg))` * chore(map): update dtslint
1 parent 1ad9425 commit d7eab2b

File tree

3 files changed

+2
-77
lines changed

3 files changed

+2
-77
lines changed

spec-dtslint/operators/map-spec.ts

-17
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ it('should support an index parameter', () => {
1313
const o = of('a', 'b', 'c').pipe(map((value, index) => index)); // $ExpectType Observable<number>
1414
});
1515

16-
it('should support an extra parameter', () => {
17-
const o = of(1, 2, 3).pipe(map(value => value, 'something')); // $ExpectType Observable<number>
18-
});
19-
2016
it('should enforce types', () => {
2117
const o = of(1, 2, 3).pipe(map()); // $ExpectError
2218
});
@@ -25,16 +21,3 @@ it('should enforce the projector types', () => {
2521
const o = of(1, 2, 3).pipe(map((value: string) => value)); // $ExpectError
2622
const p = of(1, 2, 3).pipe(map((value, index: string) => value)); // $ExpectError
2723
});
28-
29-
it('should support this', () => {
30-
const thisArg = { limit: 2 };
31-
const o = of(1, 2, 3).pipe(map(function (val) {
32-
const limit = this.limit; // $ExpectType number
33-
return val < limit ? val : limit;
34-
}, thisArg));
35-
});
36-
37-
it('should deprecate thisArg usage', () => {
38-
const a = of(1, 2, 3).pipe(map((value) => value)); // $ExpectNoDeprecation
39-
const b = of(1, 2, 3).pipe(map((value) => value, {})); // $ExpectDeprecation
40-
});

spec/operators/map-spec.ts

-52
Original file line numberDiff line numberDiff line change
@@ -213,28 +213,6 @@ describe('map', () => {
213213
});
214214
});
215215

216-
it('should map using a custom thisArg', () => {
217-
testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => {
218-
const e1 = hot('-5-^-4--3---2----1--|');
219-
const e1subs = ' ^----------------!';
220-
const expected = ' --a--b---c----d--|';
221-
const values = { a: 46, b: 55, c: 64, d: 73 };
222-
223-
const foo = {
224-
value: 42,
225-
};
226-
const result = e1.pipe(
227-
map(function (this: typeof foo, x: string, index: number) {
228-
expect(this).to.equal(foo);
229-
return parseInt(x) + foo.value + index * 10;
230-
}, foo)
231-
);
232-
233-
expectObservable(result).toBe(expected, values);
234-
expectSubscriptions(e1.subscriptions).toBe(e1subs);
235-
});
236-
});
237-
238216
it('should map twice', () => {
239217
testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => {
240218
const e1 = hot('-0----1-^-2---3--4-5--6--7-8-|');
@@ -266,36 +244,6 @@ describe('map', () => {
266244
});
267245
});
268246

269-
it('should do multiple maps using a custom thisArg', () => {
270-
testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => {
271-
const e1 = hot(' --1--2--3--4--|');
272-
const e1subs = ' ^-------------!';
273-
const expected = '--a--b--c--d--|';
274-
const values = { a: 11, b: 14, c: 17, d: 20 };
275-
276-
class Filterer {
277-
selector1 = (x: string) => parseInt(x) + 2;
278-
selector2 = (x: string) => parseInt(x) * 3;
279-
}
280-
const filterer = new Filterer();
281-
282-
const result = e1.pipe(
283-
map(function (this: any, x) {
284-
return this.selector1(x);
285-
}, filterer),
286-
map(function (this: any, x) {
287-
return this.selector2(x);
288-
}, filterer),
289-
map(function (this: any, x) {
290-
return this.selector1(x);
291-
}, filterer)
292-
);
293-
294-
expectObservable(result).toBe(expected, values);
295-
expectSubscriptions(e1.subscriptions).toBe(e1subs);
296-
});
297-
});
298-
299247
it('should not break unsubscription chain when unsubscribed explicitly', () => {
300248
testScheduler.run(({ cold, expectObservable, expectSubscriptions }) => {
301249
const e1 = cold(' --1--2--3--|');

src/internal/operators/map.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import { OperatorFunction } from '../types';
22
import { operate } from '../util/lift';
33
import { createOperatorSubscriber } from './OperatorSubscriber';
44

5-
export function map<T, R>(project: (value: T, index: number) => R): OperatorFunction<T, R>;
6-
/** @deprecated Use a closure instead of a `thisArg`. Signatures accepting a `thisArg` will be removed in v8. */
7-
export function map<T, R, A>(project: (this: A, value: T, index: number) => R, thisArg: A): OperatorFunction<T, R>;
8-
95
/**
106
* Applies a given `project` function to each value emitted by the source
117
* Observable, and emits the resulting values as an Observable.
@@ -40,12 +36,10 @@ export function map<T, R, A>(project: (this: A, value: T, index: number) => R, t
4036
* to each `value` emitted by the source Observable. The `index` parameter is
4137
* the number `i` for the i-th emission that has happened since the
4238
* subscription, starting from the number `0`.
43-
* @param {any} [thisArg] An optional argument to define what `this` is in the
44-
* `project` function.
4539
* @return A function that returns an Observable that emits the values from the
4640
* source Observable transformed by the given `project` function.
4741
*/
48-
export function map<T, R>(project: (value: T, index: number) => R, thisArg?: any): OperatorFunction<T, R> {
42+
export function map<T, R>(project: (value: T, index: number) => R): OperatorFunction<T, R> {
4943
return operate((source, subscriber) => {
5044
// The index of the value from the source. Used with projection.
5145
let index = 0;
@@ -55,7 +49,7 @@ export function map<T, R>(project: (value: T, index: number) => R, thisArg?: any
5549
createOperatorSubscriber(subscriber, (value: T) => {
5650
// Call the projection function with the appropriate this context,
5751
// and send the resulting value to the consumer.
58-
subscriber.next(project.call(thisArg, value, index++));
52+
subscriber.next(project(value, index++));
5953
})
6054
);
6155
});

0 commit comments

Comments
 (0)