Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

distinct.d.ts 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Observable } from '../Observable';
  2. import { Subscriber } from '../Subscriber';
  3. import { OuterSubscriber } from '../OuterSubscriber';
  4. import { InnerSubscriber } from '../InnerSubscriber';
  5. import { MonoTypeOperatorFunction } from '../types';
  6. /**
  7. * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items.
  8. *
  9. * If a keySelector function is provided, then it will project each value from the source observable into a new value that it will
  10. * check for equality with previously projected values. If a keySelector function is not provided, it will use each value from the
  11. * source observable directly with an equality check against previous values.
  12. *
  13. * In JavaScript runtimes that support `Set`, this operator will use a `Set` to improve performance of the distinct value checking.
  14. *
  15. * In other runtimes, this operator will use a minimal implementation of `Set` that relies on an `Array` and `indexOf` under the
  16. * hood, so performance will degrade as more values are checked for distinction. Even in newer browsers, a long-running `distinct`
  17. * use might result in memory leaks. To help alleviate this in some scenarios, an optional `flushes` parameter is also provided so
  18. * that the internal `Set` can be "flushed", basically clearing it of values.
  19. *
  20. * ## Examples
  21. * A simple example with numbers
  22. * ```javascript
  23. * of(1, 1, 2, 2, 2, 1, 2, 3, 4, 3, 2, 1).pipe(
  24. * distinct(),
  25. * )
  26. * .subscribe(x => console.log(x)); // 1, 2, 3, 4
  27. * ```
  28. *
  29. * An example using a keySelector function
  30. * ```typescript
  31. * interface Person {
  32. * age: number,
  33. * name: string
  34. * }
  35. *
  36. * of<Person>(
  37. * { age: 4, name: 'Foo'},
  38. * { age: 7, name: 'Bar'},
  39. * { age: 5, name: 'Foo'},
  40. * ).pipe(
  41. * distinct((p: Person) => p.name),
  42. * )
  43. * .subscribe(x => console.log(x));
  44. *
  45. * // displays:
  46. * // { age: 4, name: 'Foo' }
  47. * // { age: 7, name: 'Bar' }
  48. * ```
  49. * @see {@link distinctUntilChanged}
  50. * @see {@link distinctUntilKeyChanged}
  51. *
  52. * @param {function} [keySelector] Optional function to select which value you want to check as distinct.
  53. * @param {Observable} [flushes] Optional Observable for flushing the internal HashSet of the operator.
  54. * @return {Observable} An Observable that emits items from the source Observable with distinct values.
  55. * @method distinct
  56. * @owner Observable
  57. */
  58. export declare function distinct<T, K>(keySelector?: (value: T) => K, flushes?: Observable<any>): MonoTypeOperatorFunction<T>;
  59. /**
  60. * We need this JSDoc comment for affecting ESDoc.
  61. * @ignore
  62. * @extends {Ignored}
  63. */
  64. export declare class DistinctSubscriber<T, K> extends OuterSubscriber<T, T> {
  65. private keySelector;
  66. private values;
  67. constructor(destination: Subscriber<T>, keySelector: (value: T) => K, flushes: Observable<any>);
  68. notifyNext(outerValue: T, innerValue: T, outerIndex: number, innerIndex: number, innerSub: InnerSubscriber<T, T>): void;
  69. notifyError(error: any, innerSub: InnerSubscriber<T, T>): void;
  70. protected _next(value: T): void;
  71. private _useKeySelector;
  72. private _finalizeNext;
  73. }