a zip code crypto-currency system good for red ONLY

ArrayLikeObservable.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { Observable } from '../Observable';
  2. import { ScalarObservable } from './ScalarObservable';
  3. import { EmptyObservable } from './EmptyObservable';
  4. /**
  5. * We need this JSDoc comment for affecting ESDoc.
  6. * @extends {Ignored}
  7. * @hide true
  8. */
  9. export class ArrayLikeObservable extends Observable {
  10. constructor(arrayLike, scheduler) {
  11. super();
  12. this.arrayLike = arrayLike;
  13. this.scheduler = scheduler;
  14. if (!scheduler && arrayLike.length === 1) {
  15. this._isScalar = true;
  16. this.value = arrayLike[0];
  17. }
  18. }
  19. static create(arrayLike, scheduler) {
  20. const length = arrayLike.length;
  21. if (length === 0) {
  22. return new EmptyObservable();
  23. }
  24. else if (length === 1) {
  25. return new ScalarObservable(arrayLike[0], scheduler);
  26. }
  27. else {
  28. return new ArrayLikeObservable(arrayLike, scheduler);
  29. }
  30. }
  31. static dispatch(state) {
  32. const { arrayLike, index, length, subscriber } = state;
  33. if (subscriber.closed) {
  34. return;
  35. }
  36. if (index >= length) {
  37. subscriber.complete();
  38. return;
  39. }
  40. subscriber.next(arrayLike[index]);
  41. state.index = index + 1;
  42. this.schedule(state);
  43. }
  44. /** @deprecated internal use only */ _subscribe(subscriber) {
  45. let index = 0;
  46. const { arrayLike, scheduler } = this;
  47. const length = arrayLike.length;
  48. if (scheduler) {
  49. return scheduler.schedule(ArrayLikeObservable.dispatch, 0, {
  50. arrayLike, index, length, subscriber
  51. });
  52. }
  53. else {
  54. for (let i = 0; i < length && !subscriber.closed; i++) {
  55. subscriber.next(arrayLike[i]);
  56. }
  57. subscriber.complete();
  58. }
  59. }
  60. }
  61. //# sourceMappingURL=ArrayLikeObservable.js.map