Front end of the Slack clone application.

sequenceEqual.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { sequenceEqual as higherOrder } from '../operators/sequenceEqual';
  2. /**
  3. * Compares all values of two observables in sequence using an optional comparor function
  4. * and returns an observable of a single boolean value representing whether or not the two sequences
  5. * are equal.
  6. *
  7. * <span class="informal">Checks to see of all values emitted by both observables are equal, in order.</span>
  8. *
  9. * <img src="./img/sequenceEqual.png" width="100%">
  10. *
  11. * `sequenceEqual` subscribes to two observables and buffers incoming values from each observable. Whenever either
  12. * observable emits a value, the value is buffered and the buffers are shifted and compared from the bottom
  13. * up; If any value pair doesn't match, the returned observable will emit `false` and complete. If one of the
  14. * observables completes, the operator will wait for the other observable to complete; If the other
  15. * observable emits before completing, the returned observable will emit `false` and complete. If one observable never
  16. * completes or emits after the other complets, the returned observable will never complete.
  17. *
  18. * @example <caption>figure out if the Konami code matches</caption>
  19. * var code = Rx.Observable.from([
  20. * "ArrowUp",
  21. * "ArrowUp",
  22. * "ArrowDown",
  23. * "ArrowDown",
  24. * "ArrowLeft",
  25. * "ArrowRight",
  26. * "ArrowLeft",
  27. * "ArrowRight",
  28. * "KeyB",
  29. * "KeyA",
  30. * "Enter" // no start key, clearly.
  31. * ]);
  32. *
  33. * var keys = Rx.Observable.fromEvent(document, 'keyup')
  34. * .map(e => e.code);
  35. * var matches = keys.bufferCount(11, 1)
  36. * .mergeMap(
  37. * last11 =>
  38. * Rx.Observable.from(last11)
  39. * .sequenceEqual(code)
  40. * );
  41. * matches.subscribe(matched => console.log('Successful cheat at Contra? ', matched));
  42. *
  43. * @see {@link combineLatest}
  44. * @see {@link zip}
  45. * @see {@link withLatestFrom}
  46. *
  47. * @param {Observable} compareTo The observable sequence to compare the source sequence to.
  48. * @param {function} [comparor] An optional function to compare each value pair
  49. * @return {Observable} An Observable of a single boolean value representing whether or not
  50. * the values emitted by both observables were equal in sequence.
  51. * @method sequenceEqual
  52. * @owner Observable
  53. */
  54. export function sequenceEqual(compareTo, comparor) {
  55. return higherOrder(compareTo, comparor)(this);
  56. }
  57. //# sourceMappingURL=sequenceEqual.js.map