Skip to content

Commit c9b53f4

Browse files
refactor(mapTo): smaller implementation (#6393)
1 parent 9531c08 commit c9b53f4

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/internal/operators/mapTo.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { OperatorFunction } from '../types';
2-
import { operate } from '../util/lift';
3-
import { OperatorSubscriber } from './OperatorSubscriber';
2+
import { map } from './map';
43

54
export function mapTo<R>(value: R): OperatorFunction<any, R>;
65
/** @deprecated Do not specify explicit type parameters. Signatures with type parameters that cannot be inferred will be removed in v8. */
@@ -32,19 +31,10 @@ export function mapTo<T, R>(value: R): OperatorFunction<T, R>;
3231
*
3332
* @see {@link map}
3433
*
35-
* @param {any} value The value to map each source value to.
34+
* @param value The value to map each source value to.
3635
* @return A function that returns an Observable that emits the given `value`
3736
* every time the source Observable emits.
3837
*/
3938
export function mapTo<R>(value: R): OperatorFunction<any, R> {
40-
return operate((source, subscriber) => {
41-
// Subscribe to the source. All errors and completions are forwarded to the consumer
42-
source.subscribe(
43-
new OperatorSubscriber(
44-
subscriber,
45-
// On every value from the source, send the `mapTo` value to the consumer.
46-
() => subscriber.next(value)
47-
)
48-
);
49-
});
39+
return map(() => value);
5040
}

0 commit comments

Comments
 (0)