Front end of the Slack clone application.

sequenceEqual.d.ts 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { Operator } from '../Operator';
  2. import { Observer } from '../Observer';
  3. import { Observable } from '../Observable';
  4. import { Subscriber } from '../Subscriber';
  5. import { OperatorFunction } from '../interfaces';
  6. /**
  7. * Compares all values of two observables in sequence using an optional comparor function
  8. * and returns an observable of a single boolean value representing whether or not the two sequences
  9. * are equal.
  10. *
  11. * <span class="informal">Checks to see of all values emitted by both observables are equal, in order.</span>
  12. *
  13. * <img src="./img/sequenceEqual.png" width="100%">
  14. *
  15. * `sequenceEqual` subscribes to two observables and buffers incoming values from each observable. Whenever either
  16. * observable emits a value, the value is buffered and the buffers are shifted and compared from the bottom
  17. * up; If any value pair doesn't match, the returned observable will emit `false` and complete. If one of the
  18. * observables completes, the operator will wait for the other observable to complete; If the other
  19. * observable emits before completing, the returned observable will emit `false` and complete. If one observable never
  20. * completes or emits after the other complets, the returned observable will never complete.
  21. *
  22. * @example <caption>figure out if the Konami code matches</caption>
  23. * var code = Rx.Observable.from([
  24. * "ArrowUp",
  25. * "ArrowUp",
  26. * "ArrowDown",
  27. * "ArrowDown",
  28. * "ArrowLeft",
  29. * "ArrowRight",
  30. * "ArrowLeft",
  31. * "ArrowRight",
  32. * "KeyB",
  33. * "KeyA",
  34. * "Enter" // no start key, clearly.
  35. * ]);
  36. *
  37. * var keys = Rx.Observable.fromEvent(document, 'keyup')
  38. * .map(e => e.code);
  39. * var matches = keys.bufferCount(11, 1)
  40. * .mergeMap(
  41. * last11 =>
  42. * Rx.Observable.from(last11)
  43. * .sequenceEqual(code)
  44. * );
  45. * matches.subscribe(matched => console.log('Successful cheat at Contra? ', matched));
  46. *
  47. * @see {@link combineLatest}
  48. * @see {@link zip}
  49. * @see {@link withLatestFrom}
  50. *
  51. * @param {Observable} compareTo The observable sequence to compare the source sequence to.
  52. * @param {function} [comparor] An optional function to compare each value pair
  53. * @return {Observable} An Observable of a single boolean value representing whether or not
  54. * the values emitted by both observables were equal in sequence.
  55. * @method sequenceEqual
  56. * @owner Observable
  57. */
  58. export declare function sequenceEqual<T>(compareTo: Observable<T>, comparor?: (a: T, b: T) => boolean): OperatorFunction<T, boolean>;
  59. export declare class SequenceEqualOperator<T> implements Operator<T, boolean> {
  60. private compareTo;
  61. private comparor;
  62. constructor(compareTo: Observable<T>, comparor: (a: T, b: T) => boolean);
  63. call(subscriber: Subscriber<boolean>, source: any): any;
  64. }
  65. /**
  66. * We need this JSDoc comment for affecting ESDoc.
  67. * @ignore
  68. * @extends {Ignored}
  69. */
  70. export declare class SequenceEqualSubscriber<T, R> extends Subscriber<T> {
  71. private compareTo;
  72. private comparor;
  73. private _a;
  74. private _b;
  75. private _oneComplete;
  76. constructor(destination: Observer<R>, compareTo: Observable<T>, comparor: (a: T, b: T) => boolean);
  77. protected _next(value: T): void;
  78. _complete(): void;
  79. checkValues(): void;
  80. emit(value: boolean): void;
  81. nextB(value: T): void;
  82. }