distinctUntilChanged.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /* tslint:enable:max-line-length */
  5. /**
  6. * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from the previous item.
  7. *
  8. * If a comparator function is provided, then it will be called for each item to test for whether or not that value should be emitted.
  9. *
  10. * If a comparator function is not provided, an equality check is used by default.
  11. *
  12. * @example <caption>A simple example with numbers</caption>
  13. * Observable.of(1, 1, 2, 2, 2, 1, 1, 2, 3, 3, 4)
  14. * .distinctUntilChanged()
  15. * .subscribe(x => console.log(x)); // 1, 2, 1, 2, 3, 4
  16. *
  17. * @example <caption>An example using a compare function</caption>
  18. * interface Person {
  19. * age: number,
  20. * name: string
  21. * }
  22. *
  23. * Observable.of<Person>(
  24. * { age: 4, name: 'Foo'},
  25. * { age: 7, name: 'Bar'},
  26. * { age: 5, name: 'Foo'},
  27. * { age: 6, name: 'Foo'})
  28. * .distinctUntilChanged((p: Person, q: Person) => p.name === q.name)
  29. * .subscribe(x => console.log(x));
  30. *
  31. * // displays:
  32. * // { age: 4, name: 'Foo' }
  33. * // { age: 7, name: 'Bar' }
  34. * // { age: 5, name: 'Foo' }
  35. *
  36. * @see {@link distinct}
  37. * @see {@link distinctUntilKeyChanged}
  38. *
  39. * @param {function} [compare] Optional comparison function called to test if an item is distinct from the previous item in the source.
  40. * @return {Observable} An Observable that emits items from the source Observable with distinct values.
  41. * @method distinctUntilChanged
  42. * @owner Observable
  43. */
  44. function distinctUntilChanged(compare, keySelector) {
  45. return operators_1.distinctUntilChanged(compare, keySelector)(this);
  46. }
  47. exports.distinctUntilChanged = distinctUntilChanged;
  48. //# sourceMappingURL=distinctUntilChanged.js.map