find.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. * Emits only the first value emitted by the source Observable that meets some
  7. * condition.
  8. *
  9. * <span class="informal">Finds the first value that passes some test and emits
  10. * that.</span>
  11. *
  12. * <img src="./img/find.png" width="100%">
  13. *
  14. * `find` searches for the first item in the source Observable that matches the
  15. * specified condition embodied by the `predicate`, and returns the first
  16. * occurrence in the source. Unlike {@link first}, the `predicate` is required
  17. * in `find`, and does not emit an error if a valid value is not found.
  18. *
  19. * @example <caption>Find and emit the first click that happens on a DIV element</caption>
  20. * var clicks = Rx.Observable.fromEvent(document, 'click');
  21. * var result = clicks.find(ev => ev.target.tagName === 'DIV');
  22. * result.subscribe(x => console.log(x));
  23. *
  24. * @see {@link filter}
  25. * @see {@link first}
  26. * @see {@link findIndex}
  27. * @see {@link take}
  28. *
  29. * @param {function(value: T, index: number, source: Observable<T>): boolean} predicate
  30. * A function called with each item to test for condition matching.
  31. * @param {any} [thisArg] An optional argument to determine the value of `this`
  32. * in the `predicate` function.
  33. * @return {Observable<T>} An Observable of the first item that matches the
  34. * condition.
  35. * @method find
  36. * @owner Observable
  37. */
  38. function find(predicate, thisArg) {
  39. return operators_1.find(predicate, thisArg)(this);
  40. }
  41. exports.find = find;
  42. //# sourceMappingURL=find.js.map