UNPKG

@schibstedspain/openads-appnexus

Version:
159 lines (137 loc) 4.65 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = undefined; var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _timeout = require('./timeout/timeout'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * @class * @implements {AstClient} */ var AstClientImpl = function () { function AstClientImpl(_ref) { var logger = _ref.logger, apnTag = _ref.apnTag; (0, _classCallCheck3.default)(this, AstClientImpl); this._apnTag = apnTag; this._logger = logger; this._debounceTimeOutDelay = _timeout.TIMEOUT_DEBOUNCE; this._debounceTimerID = null; this._bufferTimeOutDelay = _timeout.TIMEOUT_BUFFER; this._bufferTimerID = null; this._bufferAccumulator = []; } (0, _createClass3.default)(AstClientImpl, [{ key: 'debugMode', value: function debugMode(_ref2) { var enabled = _ref2.enabled; this._apnTag.debug = enabled; return this; } }, { key: 'setPageOpts', value: function setPageOpts(data) { var _this = this; this._logger.debug(this._logger.name, '| setPageOpts | pageOpts:', data); this._apnTag.anq.push(function () { return _this._apnTag.setPageOpts(data); }); return this; } }, { key: 'onEvent', value: function onEvent(_ref3) { var _this2 = this; var event = _ref3.event, targetId = _ref3.targetId, callback = _ref3.callback; this._logger.debug(this._logger.name, '| onEvent | event:', event, '| targetId:', targetId); this._apnTag.anq.push(function () { return _this2._apnTag.onEvent(event, targetId, callback); }); return this; } }, { key: 'defineTag', value: function defineTag(data) { var _this3 = this; this._logger.debug(this._logger.name, '| defineTag | data:', data); this._apnTag.anq.push(function () { return _this3._apnTag.defineTag(data); }); return this; } }, { key: 'loadTags', value: function loadTags() { this._logger.debug(this._logger.name, '| loadTags has been requested'); if (this._debounceTimerID !== null) clearTimeout(this._debounceTimerID); this._loadTagsDebounceOperator(); return this; } }, { key: '_loadTagsDebounceOperator', value: function _loadTagsDebounceOperator() { var _this4 = this; this._debounceTimerID = setTimeout(function () { _this4._logger.debug(_this4._logger.name, '| loadTags has been called'); _this4._apnTag.anq.push(function () { return _this4._apnTag.loadTags(); }); _this4._debounceTimerID = null; }, this._debounceTimeOutDelay); } }, { key: 'showTag', value: function showTag(_ref4) { var _this5 = this; var targetId = _ref4.targetId; this._logger.debug(this._logger.name, '| showTag | targetId:', targetId); this._apnTag.anq.push(function () { return _this5._apnTag.showTag(targetId); }); return this; } }, { key: 'refresh', value: function refresh(targetsArray) { this._logger.debug(this._logger.name, '| refresh | targetsArray:', targetsArray); if (this._bufferTimerID !== null) clearTimeout(this._bufferTimerID); this._bufferAccumulator = this._bufferAccumulator.concat(targetsArray); this._refreshBufferOperator(); return this; } }, { key: '_refreshBufferOperator', value: function _refreshBufferOperator() { var _this6 = this; this._bufferTimerID = setTimeout(function () { _this6._logger.debug(_this6._logger.name, '| refresh has been called'); _this6._apnTag.anq.push(function () { return _this6._apnTag.refresh(_this6._bufferAccumulator); }); _this6._bufferTimerID = null; _this6._bufferAccumulator = []; }, this._bufferTimeOutDelay); } }, { key: 'modifyTag', value: function modifyTag(_ref5) { var _this7 = this; var targetId = _ref5.targetId, data = _ref5.data; this._logger.debug(this._logger.name, '| modifyTag | targetId:', targetId, '| data:', data); this._apnTag.anq.push(function () { return _this7._apnTag.modifyTag(targetId, data); }); return this; } }]); return AstClientImpl; }(); exports.default = AstClientImpl;