UI for Zipcoin Blue

BehaviorSubject.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 Subject_1 = require('./Subject');
  8. var ObjectUnsubscribedError_1 = require('./util/ObjectUnsubscribedError');
  9. /**
  10. * @class BehaviorSubject<T>
  11. */
  12. var BehaviorSubject = (function (_super) {
  13. __extends(BehaviorSubject, _super);
  14. function BehaviorSubject(_value) {
  15. _super.call(this);
  16. this._value = _value;
  17. }
  18. Object.defineProperty(BehaviorSubject.prototype, "value", {
  19. get: function () {
  20. return this.getValue();
  21. },
  22. enumerable: true,
  23. configurable: true
  24. });
  25. /** @deprecated internal use only */ BehaviorSubject.prototype._subscribe = function (subscriber) {
  26. var subscription = _super.prototype._subscribe.call(this, subscriber);
  27. if (subscription && !subscription.closed) {
  28. subscriber.next(this._value);
  29. }
  30. return subscription;
  31. };
  32. BehaviorSubject.prototype.getValue = function () {
  33. if (this.hasError) {
  34. throw this.thrownError;
  35. }
  36. else if (this.closed) {
  37. throw new ObjectUnsubscribedError_1.ObjectUnsubscribedError();
  38. }
  39. else {
  40. return this._value;
  41. }
  42. };
  43. BehaviorSubject.prototype.next = function (value) {
  44. _super.prototype.next.call(this, this._value = value);
  45. };
  46. return BehaviorSubject;
  47. }(Subject_1.Subject));
  48. exports.BehaviorSubject = BehaviorSubject;
  49. //# sourceMappingURL=BehaviorSubject.js.map