DropdownManager.js 807 Bytes
Newer Older
Giang Tran committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
class DropdownManager {
  _defaultDropdown = null;
  _defaultDropdownLongTime = null;

  register(_ref, _refLongTime) {
    if (!this._defaultDropdown) {
      this._defaultDropdown = _ref;
    }
    if (!this._defaultDropdownLongTime) {
      this._defaultDropdownLongTime = _refLongTime;
    }
  }

  unregister(_ref, _refLongTime) {
    if (!!this._defaultDropdown && this._defaultDropdown._id === _ref._id) {
      this._defaultDropdown = null;
    }

    if (
      !!this._defaultDropdownLongTime &&
      this._defaultDropdownLongTime._id === _refLongTime._id
    ) {
      this._defaultDropdownLongTime = null;
    }
  }

  getDefault(isLongMessage = false) {
    return isLongMessage
      ? this._defaultDropdownLongTime
      : this._defaultDropdown;
  }
}

export default new DropdownManager();