a6bb2f23455220633ee8968a5966c3d14ecaf1cf505595ea4a9068d62f9bf7164fc94d37f9009a947b39afeb45cfee99736ddf3002ae409166c783ced8ba42 1.6 KB

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