index.all.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. var core_1 = mostCore;
  12. var ProxyStream = /** @class */ (function (_super) {
  13. __extends(ProxyStream, _super);
  14. function ProxyStream() {
  15. var _this = _super.call(this, core_1.never()) || this;
  16. _this.attached = false;
  17. _this.running = false;
  18. return _this;
  19. }
  20. ProxyStream.prototype.run = function (sink, scheduler) {
  21. this.scheduler = scheduler;
  22. this.add(sink);
  23. var shouldRun = this.attached && !this.running;
  24. if (shouldRun) {
  25. this.running = true;
  26. this.disposable = this.source.run(this, scheduler);
  27. return this.disposable;
  28. }
  29. return new ProxyDisposable(this, sink);
  30. };
  31. ProxyStream.prototype.attach = function (stream) {
  32. if (this.attached)
  33. throw new Error('Can only attach 1 stream');
  34. this.attached = true;
  35. this.source = stream;
  36. var hasMoreSinks = this.sinks.length > 0;
  37. if (hasMoreSinks)
  38. this.disposable = stream.run(this, this.scheduler);
  39. return stream;
  40. };
  41. ProxyStream.prototype.error = function (time, error) {
  42. this.cleanup();
  43. _super.prototype.error.call(this, time, error);
  44. };
  45. ProxyStream.prototype.end = function (time) {
  46. this.cleanup();
  47. _super.prototype.end.call(this, time);
  48. };
  49. ProxyStream.prototype.cleanup = function () {
  50. this.attached = false;
  51. this.running = false;
  52. };
  53. return ProxyStream;
  54. }(core_1.MulticastSource));
  55. var ProxyDisposable = /** @class */ (function () {
  56. function ProxyDisposable(source, sink) {
  57. this.source = source;
  58. this.sink = sink;
  59. this.disposed = false;
  60. }
  61. ProxyDisposable.prototype.dispose = function () {
  62. if (this.disposed)
  63. return;
  64. var _a = this, source = _a.source, sink = _a.sink;
  65. this.disposed = true;
  66. var remainingSinks = source.remove(sink);
  67. var hasNoMoreSinks = remainingSinks === 0;
  68. return hasNoMoreSinks && source.dispose();
  69. };
  70. return ProxyDisposable;
  71. }());
  72. //# sourceMappingURL=ProxyStream.js.map
  73. var prelude_1 = mostPrelude;
  74. function __event(time, value, sink) {
  75. sink.event(time, value);
  76. }
  77. function __error(time, error, sink) {
  78. sink.error(time, error);
  79. }
  80. function __end(time, sink) {
  81. sink.end(time);
  82. }
  83. function create(f) {
  84. if (f === void 0) { f = prelude_1.id; }
  85. var source = new ProxyStream.ProxyStream();
  86. return [source, f(source)];
  87. }
  88. function __attach(sink, stream) {
  89. return sink.attach(stream);
  90. }
  91. let attach = prelude_1.curry2(__attach);
  92. let end = prelude_1.curry2(__end);
  93. let error = prelude_1.curry3(__error);
  94. let event = prelude_1.curry3(__event);
  95. export { attach, end, error, event, create, ProxyStream };