| 1 |
import { OperatorFunction } from '../types'; |
| 2 |
import { map } from './map'; |
| 3 |
|
| 4 |
/** @deprecated To be removed in v9. Use {@link map} instead: `map(() => value)`. */ |
| 5 |
export function mapTo<R>(value: R): OperatorFunction<unknown, R>; |
| 6 |
/** |
| 7 |
* @deprecated Do not specify explicit type parameters. Signatures with type parameters |
| 8 |
* that cannot be inferred will be removed in v8. `mapTo` itself will be removed in v9, |
| 9 |
* use {@link map} instead: `map(() => value)`. |
| 10 |
* */ |
| 11 |
export function mapTo<T, R>(value: R): OperatorFunction<T, R>; |
| 12 |
|
| 13 |
/** |
| 14 |
* Emits the given constant value on the output Observable every time the source |
| 15 |
* Observable emits a value. |
| 16 |
* |
| 17 |
* <span class="informal">Like {@link map}, but it maps every source value to |
| 18 |
* the same output value every time.</span> |
| 19 |
* |
| 20 |
*  |
| 21 |
* |
| 22 |
* Takes a constant `value` as argument, and emits that whenever the source |
| 23 |
* Observable emits a value. In other words, ignores the actual source value, |
| 24 |
* and simply uses the emission moment to know when to emit the given `value`. |
| 25 |
* |
| 26 |
* ## Example |
| 27 |
* |
| 28 |
* Map every click to the string `'Hi'` |
| 29 |
* |
| 30 |
* ```ts |
| 31 |
* import { fromEvent, mapTo } from 'rxjs'; |
| 32 |
* |
| 33 |
* const clicks = fromEvent(document, 'click'); |
| 34 |
* const greetings = clicks.pipe(mapTo('Hi')); |
| 35 |
* |
| 36 |
* greetings.subscribe(x => console.log(x)); |
| 37 |
* ``` |
| 38 |
* |
| 39 |
* @see {@link map} |
| 40 |
* |
| 41 |
* @param value The value to map each source value to. |
| 42 |
* @return A function that returns an Observable that emits the given `value` |
| 43 |
* every time the source Observable emits. |
| 44 |
* @deprecated To be removed in v9. Use {@link map} instead: `map(() => value)`. |
| 45 |
*/ |
| 46 |
export function mapTo<R>(value: R): OperatorFunction<unknown, R> { |
| 47 |
return map(() => value); |
| 48 |
} |