Front end of the Slack clone application.

skipUntil.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { OuterSubscriber } from '../OuterSubscriber';
  2. import { subscribeToResult } from '../util/subscribeToResult';
  3. /**
  4. * Returns an Observable that skips items emitted by the source Observable until a second Observable emits an item.
  5. *
  6. * <img src="./img/skipUntil.png" width="100%">
  7. *
  8. * @param {Observable} notifier - The second Observable that has to emit an item before the source Observable's elements begin to
  9. * be mirrored by the resulting Observable.
  10. * @return {Observable<T>} An Observable that skips items from the source Observable until the second Observable emits
  11. * an item, then emits the remaining items.
  12. * @method skipUntil
  13. * @owner Observable
  14. */
  15. export function skipUntil(notifier) {
  16. return (source) => source.lift(new SkipUntilOperator(notifier));
  17. }
  18. class SkipUntilOperator {
  19. constructor(notifier) {
  20. this.notifier = notifier;
  21. }
  22. call(subscriber, source) {
  23. return source.subscribe(new SkipUntilSubscriber(subscriber, this.notifier));
  24. }
  25. }
  26. /**
  27. * We need this JSDoc comment for affecting ESDoc.
  28. * @ignore
  29. * @extends {Ignored}
  30. */
  31. class SkipUntilSubscriber extends OuterSubscriber {
  32. constructor(destination, notifier) {
  33. super(destination);
  34. this.hasValue = false;
  35. this.isInnerStopped = false;
  36. this.add(subscribeToResult(this, notifier));
  37. }
  38. _next(value) {
  39. if (this.hasValue) {
  40. super._next(value);
  41. }
  42. }
  43. _complete() {
  44. if (this.isInnerStopped) {
  45. super._complete();
  46. }
  47. else {
  48. this.unsubscribe();
  49. }
  50. }
  51. notifyNext(outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  52. this.hasValue = true;
  53. }
  54. notifyComplete() {
  55. this.isInnerStopped = true;
  56. if (this.isStopped) {
  57. super._complete();
  58. }
  59. }
  60. }
  61. //# sourceMappingURL=skipUntil.js.map