distinctUntilKeyChanged.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. * using a property accessed by using the key provided to check if the two items are distinct.
  8. *
  9. * 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.
  10. *
  11. * If a comparator function is not provided, an equality check is used by default.
  12. *
  13. * @example <caption>An example comparing the name of persons</caption>
  14. *
  15. * interface Person {
  16. * age: number,
  17. * name: string
  18. * }
  19. *
  20. * Observable.of<Person>(
  21. * { age: 4, name: 'Foo'},
  22. * { age: 7, name: 'Bar'},
  23. * { age: 5, name: 'Foo'},
  24. * { age: 6, name: 'Foo'})
  25. * .distinctUntilKeyChanged('name')
  26. * .subscribe(x => console.log(x));
  27. *
  28. * // displays:
  29. * // { age: 4, name: 'Foo' }
  30. * // { age: 7, name: 'Bar' }
  31. * // { age: 5, name: 'Foo' }
  32. *
  33. * @example <caption>An example comparing the first letters of the name</caption>
  34. *
  35. * interface Person {
  36. * age: number,
  37. * name: string
  38. * }
  39. *
  40. * Observable.of<Person>(
  41. * { age: 4, name: 'Foo1'},
  42. * { age: 7, name: 'Bar'},
  43. * { age: 5, name: 'Foo2'},
  44. * { age: 6, name: 'Foo3'})
  45. * .distinctUntilKeyChanged('name', (x: string, y: string) => x.substring(0, 3) === y.substring(0, 3))
  46. * .subscribe(x => console.log(x));
  47. *
  48. * // displays:
  49. * // { age: 4, name: 'Foo1' }
  50. * // { age: 7, name: 'Bar' }
  51. * // { age: 5, name: 'Foo2' }
  52. *
  53. * @see {@link distinct}
  54. * @see {@link distinctUntilChanged}
  55. *
  56. * @param {string} key String key for object property lookup on each item.
  57. * @param {function} [compare] Optional comparison function called to test if an item is distinct from the previous item in the source.
  58. * @return {Observable} An Observable that emits items from the source Observable with distinct values based on the key specified.
  59. * @method distinctUntilKeyChanged
  60. * @owner Observable
  61. */
  62. // tslint:disable-next-line:max-line-length
  63. function distinctUntilKeyChanged(key, compare) {
  64. return operators_1.distinctUntilKeyChanged(key, compare)(this);
  65. }
  66. exports.distinctUntilKeyChanged = distinctUntilKeyChanged;
  67. //# sourceMappingURL=distinctUntilKeyChanged.js.map