Skip to content

refactor(mapTo): smaller implementation #6393

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

Merged
merged 1 commit into from
May 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions src/internal/operators/mapTo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { OperatorFunction } from '../types';
import { operate } from '../util/lift';
import { OperatorSubscriber } from './OperatorSubscriber';
import { map } from './map';

export function mapTo<R>(value: R): OperatorFunction<any, R>;
/** @deprecated Do not specify explicit type parameters. Signatures with type parameters that cannot be inferred will be removed in v8. */
Expand Down Expand Up @@ -32,19 +31,10 @@ export function mapTo<T, R>(value: R): OperatorFunction<T, R>;
*
* @see {@link map}
*
* @param {any} value The value to map each source value to.
* @param value The value to map each source value to.
* @return A function that returns an Observable that emits the given `value`
* every time the source Observable emits.
*/
export function mapTo<R>(value: R): OperatorFunction<any, R> {
return operate((source, subscriber) => {
// Subscribe to the source. All errors and completions are forwarded to the consumer
source.subscribe(
new OperatorSubscriber(
subscriber,
// On every value from the source, send the `mapTo` value to the consumer.
() => subscriber.next(value)
)
);
});
return map(() => value);
}