3a706207340edb97dc0930af2cfbb076c2bd43b4c0947ae02967019bb099dabbfd97b9a4cc0b8f6311a3540c1832229ef3f1e4d8e0db072f48000284f85460 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { SchedulerLike, ValueFromArray } from '../types';
  2. import { Observable } from '../Observable';
  3. import { popScheduler } from '../util/args';
  4. import { from } from './from';
  5. // Devs are more likely to pass null or undefined than they are a scheduler
  6. // without accompanying values. To make things easier for (naughty) devs who
  7. // use the `strictNullChecks: false` TypeScript compiler option, these
  8. // overloads with explicit null and undefined values are included.
  9. export function of(value: null): Observable<null>;
  10. export function of(value: undefined): Observable<undefined>;
  11. /** @deprecated The `scheduler` parameter will be removed in v8. Use `scheduled`. Details: https://rxjs.dev/deprecations/scheduler-argument */
  12. export function of(scheduler: SchedulerLike): Observable<never>;
  13. /** @deprecated The `scheduler` parameter will be removed in v8. Use `scheduled`. Details: https://rxjs.dev/deprecations/scheduler-argument */
  14. export function of<A extends readonly unknown[]>(...valuesAndScheduler: [...A, SchedulerLike]): Observable<ValueFromArray<A>>;
  15. export function of(): Observable<never>;
  16. /** @deprecated Do not specify explicit type parameters. Signatures with type parameters that cannot be inferred will be removed in v8. */
  17. export function of<T>(): Observable<T>;
  18. export function of<T>(value: T): Observable<T>;
  19. export function of<A extends readonly unknown[]>(...values: A): Observable<ValueFromArray<A>>;
  20. /**
  21. * Converts the arguments to an observable sequence.
  22. *
  23. * <span class="informal">Each argument becomes a `next` notification.</span>
  24. *
  25. * ![](of.png)
  26. *
  27. * Unlike {@link from}, it does not do any flattening and emits each argument in whole
  28. * as a separate `next` notification.
  29. *
  30. * ## Examples
  31. *
  32. * Emit the values `10, 20, 30`
  33. *
  34. * ```ts
  35. * import { of } from 'rxjs';
  36. *
  37. * of(10, 20, 30)
  38. * .subscribe({
  39. * next: value => console.log('next:', value),
  40. * error: err => console.log('error:', err),
  41. * complete: () => console.log('the end'),
  42. * });
  43. *
  44. * // Outputs
  45. * // next: 10
  46. * // next: 20
  47. * // next: 30
  48. * // the end
  49. * ```
  50. *
  51. * Emit the array `[1, 2, 3]`
  52. *
  53. * ```ts
  54. * import { of } from 'rxjs';
  55. *
  56. * of([1, 2, 3])
  57. * .subscribe({
  58. * next: value => console.log('next:', value),
  59. * error: err => console.log('error:', err),
  60. * complete: () => console.log('the end'),
  61. * });
  62. *
  63. * // Outputs
  64. * // next: [1, 2, 3]
  65. * // the end
  66. * ```
  67. *
  68. * @see {@link from}
  69. * @see {@link range}
  70. *
  71. * @param args A comma separated list of arguments you want to be emitted.
  72. * @return An Observable that synchronously emits the arguments described
  73. * above and then immediately completes.
  74. */
  75. export function of<T>(...args: Array<T | SchedulerLike>): Observable<T> {
  76. const scheduler = popScheduler(args);
  77. return from(args as T[], scheduler);
  78. }