BehaviorSubject.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. exports.BehaviorSubject = void 0;
  19. var Subject_1 = require("./Subject");
  20. var BehaviorSubject = (function (_super) {
  21. __extends(BehaviorSubject, _super);
  22. function BehaviorSubject(_value) {
  23. var _this = _super.call(this) || this;
  24. _this._value = _value;
  25. return _this;
  26. }
  27. Object.defineProperty(BehaviorSubject.prototype, "value", {
  28. get: function () {
  29. return this.getValue();
  30. },
  31. enumerable: false,
  32. configurable: true
  33. });
  34. BehaviorSubject.prototype._subscribe = function (subscriber) {
  35. var subscription = _super.prototype._subscribe.call(this, subscriber);
  36. !subscription.closed && subscriber.next(this._value);
  37. return subscription;
  38. };
  39. BehaviorSubject.prototype.getValue = function () {
  40. var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, _value = _a._value;
  41. if (hasError) {
  42. throw thrownError;
  43. }
  44. this._throwIfClosed();
  45. return _value;
  46. };
  47. BehaviorSubject.prototype.next = function (value) {
  48. _super.prototype.next.call(this, (this._value = value));
  49. };
  50. return BehaviorSubject;
  51. }(Subject_1.Subject));
  52. exports.BehaviorSubject = BehaviorSubject;
  53. //# sourceMappingURL=BehaviorSubject.js.map