UNPKG

@adv-ui/boros-tcf

Version:

Adevinta GDPR - Transparency and Consent Framework - API

123 lines (94 loc) 3.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventStatusService = void 0; var _ioc = require("../../core/ioc/ioc"); var _DomainEventBus = require("./DomainEventBus"); var _GetTCDataUseCase = require("../../application/services/tcdata/GetTCDataUseCase"); var _StatusRepository = require("../status/StatusRepository"); var _Status = require("../status/Status"); var EventStatusService = /*#__PURE__*/function () { function EventStatusService(_temp) { var _ref = _temp === void 0 ? {} : _temp, _ref$domainEventBus = _ref.domainEventBus, domainEventBus = _ref$domainEventBus === void 0 ? (0, _ioc.inject)(_DomainEventBus.DomainEventBus) : _ref$domainEventBus, _ref$getTCDataUseCase = _ref.getTCDataUseCase, getTCDataUseCase = _ref$getTCDataUseCase === void 0 ? (0, _ioc.inject)(_GetTCDataUseCase.GetTCDataUseCase) : _ref$getTCDataUseCase, _ref$statusRepository = _ref.statusRepository, statusRepository = _ref$statusRepository === void 0 ? (0, _ioc.inject)(_StatusRepository.StatusRepository) : _ref$statusRepository; this._domainEventBus = domainEventBus; this._getTCDataUseCase = getTCDataUseCase; this._status = statusRepository.getStatus(); } var _proto = EventStatusService.prototype; _proto._getEventStatus = function _getEventStatus() { var _this$_status = this._status, cmpStatus = _this$_status.cmpStatus, displayStatus = _this$_status.displayStatus; var eventStatus = null; if (cmpStatus === _Status.Status.CMPSTATUS_LOADED) { eventStatus = _Status.Status.TCLOADED; } switch (displayStatus) { case _Status.Status.DISPLAYSTATUS_VISIBLE: eventStatus = _Status.Status.CMPUISHOWN; break; case _Status.Status.DISPLAYSTATUS_HIDDEN: eventStatus = _Status.Status.USERACTIONCOMPLETE; break; } return eventStatus; }; _proto.updateUiStatus = function updateUiStatus() { this._status.eventStatus = this._getEventStatus(); var tcData = this._getTCDataUseCase.execute(); this._domainEventBus.raise({ eventName: EVENT_STATUS, payload: { TCData: tcData } }); }; _proto.updateTCLoaded = function updateTCLoaded(_ref2) { var notify = _ref2.notify; this._status.eventStatus = this._getEventStatus(); if (notify) { var tcData = this._getTCDataUseCase.execute(); this._domainEventBus.raise({ eventName: EVENT_STATUS, payload: { TCData: tcData } }); } }; _proto.addEventListener = function addEventListener(_ref3) { var callback = _ref3.callback; var reference; try { reference = this._domainEventBus.register({ eventName: EVENT_STATUS, observer: callback }); } catch (error) { typeof callback === 'function' && callback(null, false); return; } var tcData = this._getTCDataUseCase.execute(); tcData.listenerId = reference; typeof callback === 'function' && callback(tcData, true); }; _proto.removeEventListener = function removeEventListener(_ref4) { var callback = _ref4.callback, listenerId = _ref4.listenerId; var success = this._domainEventBus.unregister({ eventName: EVENT_STATUS, reference: listenerId }); typeof callback === 'function' && callback(success); }; return EventStatusService; }(); exports.EventStatusService = EventStatusService; var EVENT_STATUS = 'event_status';