Front end of the Slack clone application.

ArrayLikeObservable.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  4. function __() { this.constructor = d; }
  5. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6. };
  7. var Observable_1 = require('../Observable');
  8. var ScalarObservable_1 = require('./ScalarObservable');
  9. var EmptyObservable_1 = require('./EmptyObservable');
  10. /**
  11. * We need this JSDoc comment for affecting ESDoc.
  12. * @extends {Ignored}
  13. * @hide true
  14. */
  15. var ArrayLikeObservable = (function (_super) {
  16. __extends(ArrayLikeObservable, _super);
  17. function ArrayLikeObservable(arrayLike, scheduler) {
  18. _super.call(this);
  19. this.arrayLike = arrayLike;
  20. this.scheduler = scheduler;
  21. if (!scheduler && arrayLike.length === 1) {
  22. this._isScalar = true;
  23. this.value = arrayLike[0];
  24. }
  25. }
  26. ArrayLikeObservable.create = function (arrayLike, scheduler) {
  27. var length = arrayLike.length;
  28. if (length === 0) {
  29. return new EmptyObservable_1.EmptyObservable();
  30. }
  31. else if (length === 1) {
  32. return new ScalarObservable_1.ScalarObservable(arrayLike[0], scheduler);
  33. }
  34. else {
  35. return new ArrayLikeObservable(arrayLike, scheduler);
  36. }
  37. };
  38. ArrayLikeObservable.dispatch = function (state) {
  39. var arrayLike = state.arrayLike, index = state.index, length = state.length, subscriber = state.subscriber;
  40. if (subscriber.closed) {
  41. return;
  42. }
  43. if (index >= length) {
  44. subscriber.complete();
  45. return;
  46. }
  47. subscriber.next(arrayLike[index]);
  48. state.index = index + 1;
  49. this.schedule(state);
  50. };
  51. /** @deprecated internal use only */ ArrayLikeObservable.prototype._subscribe = function (subscriber) {
  52. var index = 0;
  53. var _a = this, arrayLike = _a.arrayLike, scheduler = _a.scheduler;
  54. var length = arrayLike.length;
  55. if (scheduler) {
  56. return scheduler.schedule(ArrayLikeObservable.dispatch, 0, {
  57. arrayLike: arrayLike, index: index, length: length, subscriber: subscriber
  58. });
  59. }
  60. else {
  61. for (var i = 0; i < length && !subscriber.closed; i++) {
  62. subscriber.next(arrayLike[i]);
  63. }
  64. subscriber.complete();
  65. }
  66. };
  67. return ArrayLikeObservable;
  68. }(Observable_1.Observable));
  69. exports.ArrayLikeObservable = ArrayLikeObservable;
  70. //# sourceMappingURL=ArrayLikeObservable.js.map