{"ast":null,"code":"import _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 { Subscriber } from '../Subscriber';\nimport { Subscription } from '../Subscription';\nimport { Observable } from '../Observable';\nimport { Subject } from '../Subject';\nexport function groupBy(keySelector, elementSelector, durationSelector, subjectSelector) {\n  return function (source) {\n    return source.lift(new GroupByOperator(keySelector, elementSelector, durationSelector, subjectSelector));\n  };\n}\n\nvar GroupByOperator = /*#__PURE__*/function () {\n  function GroupByOperator(keySelector, elementSelector, durationSelector, subjectSelector) {\n    _classCallCheck(this, GroupByOperator);\n\n    this.keySelector = keySelector;\n    this.elementSelector = elementSelector;\n    this.durationSelector = durationSelector;\n    this.subjectSelector = subjectSelector;\n  }\n\n  _createClass(GroupByOperator, [{\n    key: \"call\",\n    value: function call(subscriber, source) {\n      return source.subscribe(new GroupBySubscriber(subscriber, this.keySelector, this.elementSelector, this.durationSelector, this.subjectSelector));\n    }\n  }]);\n\n  return GroupByOperator;\n}();\n\nvar GroupBySubscriber = /*#__PURE__*/function (_Subscriber) {\n  _inherits(GroupBySubscriber, _Subscriber);\n\n  var _super = _createSuper(GroupBySubscriber);\n\n  function GroupBySubscriber(destination, keySelector, elementSelector, durationSelector, subjectSelector) {\n    var _this;\n\n    _classCallCheck(this, GroupBySubscriber);\n\n    _this = _super.call(this, destination);\n    _this.keySelector = keySelector;\n    _this.elementSelector = elementSelector;\n    _this.durationSelector = durationSelector;\n    _this.subjectSelector = subjectSelector;\n    _this.groups = null;\n    _this.attemptedToUnsubscribe = false;\n    _this.count = 0;\n    return _this;\n  }\n\n  _createClass(GroupBySubscriber, [{\n    key: \"_next\",\n    value: function _next(value) {\n      var key;\n\n      try {\n        key = this.keySelector(value);\n      } catch (err) {\n        this.error(err);\n        return;\n      }\n\n      this._group(value, key);\n    }\n  }, {\n    key: \"_group\",\n    value: function _group(value, key) {\n      var groups = this.groups;\n\n      if (!groups) {\n        groups = this.groups = new Map();\n      }\n\n      var group = groups.get(key);\n      var element;\n\n      if (this.elementSelector) {\n        try {\n          element = this.elementSelector(value);\n        } catch (err) {\n          this.error(err);\n        }\n      } else {\n        element = value;\n      }\n\n      if (!group) {\n        group = this.subjectSelector ? this.subjectSelector() : new Subject();\n        groups.set(key, group);\n        var groupedObservable = new GroupedObservable(key, group, this);\n        this.destination.next(groupedObservable);\n\n        if (this.durationSelector) {\n          var duration;\n\n          try {\n            duration = this.durationSelector(new GroupedObservable(key, group));\n          } catch (err) {\n            this.error(err);\n            return;\n          }\n\n          this.add(duration.subscribe(new GroupDurationSubscriber(key, group, this)));\n        }\n      }\n\n      if (!group.closed) {\n        group.next(element);\n      }\n    }\n  }, {\n    key: \"_error\",\n    value: function _error(err) {\n      var groups = this.groups;\n\n      if (groups) {\n        groups.forEach(function (group, key) {\n          group.error(err);\n        });\n        groups.clear();\n      }\n\n      this.destination.error(err);\n    }\n  }, {\n    key: \"_complete\",\n    value: function _complete() {\n      var groups = this.groups;\n\n      if (groups) {\n        groups.forEach(function (group, key) {\n          group.complete();\n        });\n        groups.clear();\n      }\n\n      this.destination.complete();\n    }\n  }, {\n    key: \"removeGroup\",\n    value: function removeGroup(key) {\n      this.groups.delete(key);\n    }\n  }, {\n    key: \"unsubscribe\",\n    value: function unsubscribe() {\n      if (!this.closed) {\n        this.attemptedToUnsubscribe = true;\n\n        if (this.count === 0) {\n          _get(_getPrototypeOf(GroupBySubscriber.prototype), \"unsubscribe\", this).call(this);\n        }\n      }\n    }\n  }]);\n\n  return GroupBySubscriber;\n}(Subscriber);\n\nvar GroupDurationSubscriber = /*#__PURE__*/function (_Subscriber2) {\n  _inherits(GroupDurationSubscriber, _Subscriber2);\n\n  var _super2 = _createSuper(GroupDurationSubscriber);\n\n  function GroupDurationSubscriber(key, group, parent) {\n    var _this2;\n\n    _classCallCheck(this, GroupDurationSubscriber);\n\n    _this2 = _super2.call(this, group);\n    _this2.key = key;\n    _this2.group = group;\n    _this2.parent = parent;\n    return _this2;\n  }\n\n  _createClass(GroupDurationSubscriber, [{\n    key: \"_next\",\n    value: function _next(value) {\n      this.complete();\n    }\n  }, {\n    key: \"_unsubscribe\",\n    value: function _unsubscribe() {\n      var parent = this.parent,\n          key = this.key;\n      this.key = this.parent = null;\n\n      if (parent) {\n        parent.removeGroup(key);\n      }\n    }\n  }]);\n\n  return GroupDurationSubscriber;\n}(Subscriber);\n\nexport var GroupedObservable = /*#__PURE__*/function (_Observable) {\n  _inherits(GroupedObservable, _Observable);\n\n  var _super3 = _createSuper(GroupedObservable);\n\n  function GroupedObservable(key, groupSubject, refCountSubscription) {\n    var _this3;\n\n    _classCallCheck(this, GroupedObservable);\n\n    _this3 = _super3.call(this);\n    _this3.key = key;\n    _this3.groupSubject = groupSubject;\n    _this3.refCountSubscription = refCountSubscription;\n    return _this3;\n  }\n\n  _createClass(GroupedObservable, [{\n    key: \"_subscribe\",\n    value: function _subscribe(subscriber) {\n      var subscription = new Subscription();\n      var refCountSubscription = this.refCountSubscription,\n          groupSubject = this.groupSubject;\n\n      if (refCountSubscription && !refCountSubscription.closed) {\n        subscription.add(new InnerRefCountSubscription(refCountSubscription));\n      }\n\n      subscription.add(groupSubject.subscribe(subscriber));\n      return subscription;\n    }\n  }]);\n\n  return GroupedObservable;\n}(Observable);\n\nvar InnerRefCountSubscription = /*#__PURE__*/function (_Subscription) {\n  _inherits(InnerRefCountSubscription, _Subscription);\n\n  var _super4 = _createSuper(InnerRefCountSubscription);\n\n  function InnerRefCountSubscription(parent) {\n    var _this4;\n\n    _classCallCheck(this, InnerRefCountSubscription);\n\n    _this4 = _super4.call(this);\n    _this4.parent = parent;\n    parent.count++;\n    return _this4;\n  }\n\n  _createClass(InnerRefCountSubscription, [{\n    key: \"unsubscribe\",\n    value: function unsubscribe() {\n      var parent = this.parent;\n\n      if (!parent.closed && !this.closed) {\n        _get(_getPrototypeOf(InnerRefCountSubscription.prototype), \"unsubscribe\", this).call(this);\n\n        parent.count -= 1;\n\n        if (parent.count === 0 && parent.attemptedToUnsubscribe) {\n          parent.unsubscribe();\n        }\n      }\n    }\n  }]);\n\n  return InnerRefCountSubscription;\n}(Subscription); //# sourceMappingURL=groupBy.js.map","map":null,"metadata":{},"sourceType":"module"}