{"ast":null,"code":"import _assertThisInitialized from \"C:/Users/kgamal/Downloads/HijriGregorianDatepicker-master/HijriGregorianDatepicker-master/node_modules/@babel/runtime/helpers/esm/assertThisInitialized\";\nimport _get from \"C:/Users/kgamal/Downloads/HijriGregorianDatepicker-master/HijriGregorianDatepicker-master/node_modules/@babel/runtime/helpers/esm/get\";\nimport _getPrototypeOf from \"C:/Users/kgamal/Downloads/HijriGregorianDatepicker-master/HijriGregorianDatepicker-master/node_modules/@babel/runtime/helpers/esm/getPrototypeOf\";\nimport _inherits from \"C:/Users/kgamal/Downloads/HijriGregorianDatepicker-master/HijriGregorianDatepicker-master/node_modules/@babel/runtime/helpers/esm/inherits\";\nimport _createSuper from \"C:/Users/kgamal/Downloads/HijriGregorianDatepicker-master/HijriGregorianDatepicker-master/node_modules/@babel/runtime/helpers/esm/createSuper\";\nimport _classCallCheck from \"C:/Users/kgamal/Downloads/HijriGregorianDatepicker-master/HijriGregorianDatepicker-master/node_modules/@babel/runtime/helpers/esm/classCallCheck\";\nimport _createClass from \"C:/Users/kgamal/Downloads/HijriGregorianDatepicker-master/HijriGregorianDatepicker-master/node_modules/@babel/runtime/helpers/esm/createClass\";\nimport { Subscription } from '../Subscription';\nimport { subscribeToResult } from '../util/subscribeToResult';\nimport { OuterSubscriber } from '../OuterSubscriber';\nexport function bufferToggle(openings, closingSelector) {\n  return function bufferToggleOperatorFunction(source) {\n    return source.lift(new BufferToggleOperator(openings, closingSelector));\n  };\n}\n\nvar BufferToggleOperator = /*#__PURE__*/function () {\n  function BufferToggleOperator(openings, closingSelector) {\n    _classCallCheck(this, BufferToggleOperator);\n\n    this.openings = openings;\n    this.closingSelector = closingSelector;\n  }\n\n  _createClass(BufferToggleOperator, [{\n    key: \"call\",\n    value: function call(subscriber, source) {\n      return source.subscribe(new BufferToggleSubscriber(subscriber, this.openings, this.closingSelector));\n    }\n  }]);\n\n  return BufferToggleOperator;\n}();\n\nvar BufferToggleSubscriber = /*#__PURE__*/function (_OuterSubscriber) {\n  _inherits(BufferToggleSubscriber, _OuterSubscriber);\n\n  var _super = _createSuper(BufferToggleSubscriber);\n\n  function BufferToggleSubscriber(destination, openings, closingSelector) {\n    var _this;\n\n    _classCallCheck(this, BufferToggleSubscriber);\n\n    _this = _super.call(this, destination);\n    _this.closingSelector = closingSelector;\n    _this.contexts = [];\n\n    _this.add(subscribeToResult(_assertThisInitialized(_this), openings));\n\n    return _this;\n  }\n\n  _createClass(BufferToggleSubscriber, [{\n    key: \"_next\",\n    value: function _next(value) {\n      var contexts = this.contexts;\n      var len = contexts.length;\n\n      for (var i = 0; i < len; i++) {\n        contexts[i].buffer.push(value);\n      }\n    }\n  }, {\n    key: \"_error\",\n    value: function _error(err) {\n      var contexts = this.contexts;\n\n      while (contexts.length > 0) {\n        var context = contexts.shift();\n        context.subscription.unsubscribe();\n        context.buffer = null;\n        context.subscription = null;\n      }\n\n      this.contexts = null;\n\n      _get(_getPrototypeOf(BufferToggleSubscriber.prototype), \"_error\", this).call(this, err);\n    }\n  }, {\n    key: \"_complete\",\n    value: function _complete() {\n      var contexts = this.contexts;\n\n      while (contexts.length > 0) {\n        var context = contexts.shift();\n        this.destination.next(context.buffer);\n        context.subscription.unsubscribe();\n        context.buffer = null;\n        context.subscription = null;\n      }\n\n      this.contexts = null;\n\n      _get(_getPrototypeOf(BufferToggleSubscriber.prototype), \"_complete\", this).call(this);\n    }\n  }, {\n    key: \"notifyNext\",\n    value: function notifyNext(outerValue, innerValue) {\n      outerValue ? this.closeBuffer(outerValue) : this.openBuffer(innerValue);\n    }\n  }, {\n    key: \"notifyComplete\",\n    value: function notifyComplete(innerSub) {\n      this.closeBuffer(innerSub.context);\n    }\n  }, {\n    key: \"openBuffer\",\n    value: function openBuffer(value) {\n      try {\n        var closingSelector = this.closingSelector;\n        var closingNotifier = closingSelector.call(this, value);\n\n        if (closingNotifier) {\n          this.trySubscribe(closingNotifier);\n        }\n      } catch (err) {\n        this._error(err);\n      }\n    }\n  }, {\n    key: \"closeBuffer\",\n    value: function closeBuffer(context) {\n      var contexts = this.contexts;\n\n      if (contexts && context) {\n        var buffer = context.buffer,\n            subscription = context.subscription;\n        this.destination.next(buffer);\n        contexts.splice(contexts.indexOf(context), 1);\n        this.remove(subscription);\n        subscription.unsubscribe();\n      }\n    }\n  }, {\n    key: \"trySubscribe\",\n    value: function trySubscribe(closingNotifier) {\n      var contexts = this.contexts;\n      var buffer = [];\n      var subscription = new Subscription();\n      var context = {\n        buffer: buffer,\n        subscription: subscription\n      };\n      contexts.push(context);\n      var innerSubscription = subscribeToResult(this, closingNotifier, context);\n\n      if (!innerSubscription || innerSubscription.closed) {\n        this.closeBuffer(context);\n      } else {\n        innerSubscription.context = context;\n        this.add(innerSubscription);\n        subscription.add(innerSubscription);\n      }\n    }\n  }]);\n\n  return BufferToggleSubscriber;\n}(OuterSubscriber); //# sourceMappingURL=bufferToggle.js.map","map":null,"metadata":{},"sourceType":"module"}