@advertol/core
Advanced tools
Comparing version 1.0.1-alpha.0 to 1.0.1
303
index.cjs.js
@@ -6,6 +6,5 @@ 'use strict'; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -17,12 +16,8 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
var Zone = | ||
/*#__PURE__*/ | ||
function () { | ||
var Zone = /*#__PURE__*/function () { | ||
/** | ||
@@ -36,7 +31,5 @@ * @param {string} id | ||
} | ||
if (element instanceof HTMLElement === false) { | ||
throw new TypeError('Expected an element.'); | ||
} | ||
this.id = id; | ||
@@ -48,13 +41,9 @@ this.element = element; | ||
} | ||
var _proto = Zone.prototype; | ||
_proto.show = function show() { | ||
this.isVisible = true; | ||
}; | ||
_proto.hide = function hide() { | ||
this.isVisible = false; | ||
}; | ||
_proto.setAsLoaded = function setAsLoaded() { | ||
@@ -64,3 +53,2 @@ this.isLoaded = true; | ||
}; | ||
_proto.setAsEmpty = function setAsEmpty() { | ||
@@ -70,7 +58,5 @@ this.isLoaded = true; | ||
}; | ||
_proto.destroy = function destroy() { | ||
this.isVisible = false; | ||
}; | ||
return Zone; | ||
@@ -81,9 +67,7 @@ }(); | ||
var key = _ref.key, | ||
cache = _ref.cache, | ||
result = _ref.result; | ||
cache = _ref.cache, | ||
result = _ref.result; | ||
if (cache[key] instanceof Promise) { | ||
return cache[key]; | ||
} | ||
cache[key] = result(); | ||
@@ -98,3 +82,2 @@ return cache[key]; | ||
*/ | ||
function filterById(zoneIds) { | ||
@@ -111,6 +94,3 @@ /** | ||
} | ||
var Zones = | ||
/*#__PURE__*/ | ||
function () { | ||
var Zones = /*#__PURE__*/function () { | ||
/** | ||
@@ -123,3 +103,2 @@ * @param {Zone[]} zones | ||
var _this = this; | ||
this.instances = []; | ||
@@ -133,9 +112,7 @@ this.writeResults = {}; | ||
} | ||
/** | ||
* @param {Zone} zone | ||
*/ | ||
var _proto = Zones.prototype; | ||
_proto.add = function add(zone) { | ||
@@ -145,6 +122,4 @@ if (zone instanceof Zone === false) { | ||
} | ||
var element = zone.element, | ||
id = zone.id; | ||
id = zone.id; | ||
if (this.instances.some(function (_ref2) { | ||
@@ -156,3 +131,2 @@ var existingId = _ref2.id; | ||
} | ||
this.instances.push(zone); | ||
@@ -164,2 +138,3 @@ this.service.afterZoneRegistered({ | ||
} | ||
/** | ||
@@ -169,8 +144,5 @@ * @param {string[]} zoneIds | ||
* @return {Promise<Zone[]>} | ||
*/ | ||
; | ||
*/; | ||
_proto.show = function show(zoneIds) { | ||
var _this2 = this; | ||
var boundFilterById = filterById(zoneIds); | ||
@@ -184,7 +156,5 @@ var zones = this.instances.filter(boundFilterById); | ||
zone.show(); | ||
if (isInitiallyVisible) { | ||
return Promise.resolve(zone); | ||
} | ||
return _this2.controlResolver.resolve(zone).then(function () { | ||
@@ -196,2 +166,3 @@ return zone; | ||
} | ||
/** | ||
@@ -201,8 +172,5 @@ * @param {string[]} zoneIds | ||
* @return {Promise<Zone[]>} | ||
*/ | ||
; | ||
*/; | ||
_proto.hide = function hide(zoneIds) { | ||
var _this3 = this; | ||
var boundFilterById = filterById(zoneIds); | ||
@@ -216,7 +184,5 @@ var zones = this.instances.filter(boundFilterById); | ||
zone.hide(); | ||
if (!isInitiallyVisible) { | ||
return Promise.resolve(zone); | ||
} | ||
return _this3.controlResolver.resolve(zone).then(function () { | ||
@@ -228,2 +194,3 @@ return zone; | ||
} | ||
/** | ||
@@ -233,8 +200,5 @@ * @param {string[]} zoneIds | ||
* @return {Promise<Zone[]>} | ||
*/ | ||
; | ||
*/; | ||
_proto.write = function write(zoneIds) { | ||
var _this4 = this; | ||
var boundFilterById = filterById(zoneIds); | ||
@@ -247,3 +211,3 @@ var zones = this.instances.filter(boundFilterById).filter(function (_ref5) { | ||
var element = _ref6.element, | ||
id = _ref6.id; | ||
id = _ref6.id; | ||
return { | ||
@@ -257,3 +221,3 @@ element: element, | ||
var element = zone.element, | ||
id = zone.id; | ||
id = zone.id; | ||
var writePromise = memoizePromise({ | ||
@@ -271,3 +235,2 @@ key: id, | ||
var isEmpty = !hasContent; | ||
if (isEmpty) { | ||
@@ -278,10 +241,7 @@ zone.setAsEmpty(); | ||
} | ||
var isInitiallyVisible = zone.isVisible; | ||
zone.show(); | ||
if (isInitiallyVisible) { | ||
return Promise.resolve(zone); | ||
} | ||
return _this4.controlResolver.resolve(zone).then(function () { | ||
@@ -296,3 +256,2 @@ return zone; | ||
}; | ||
_proto.destroy = function destroy() { | ||
@@ -304,9 +263,6 @@ this.instances.forEach(function (zone) { | ||
}; | ||
return Zones; | ||
}(); | ||
var Control = | ||
/*#__PURE__*/ | ||
function () { | ||
var Control = /*#__PURE__*/function () { | ||
function Control() { | ||
@@ -316,2 +272,3 @@ this._shouldTriggerControlCache = {}; | ||
} | ||
/** | ||
@@ -325,9 +282,7 @@ * @param {Object} options | ||
*/ | ||
var _proto = Control.prototype; | ||
_proto.shouldTriggerControl = function shouldTriggerControl() { | ||
return Promise.resolve(false); | ||
} | ||
/** | ||
@@ -340,8 +295,7 @@ * @param {Object} options | ||
* @return {Promise<*>} | ||
*/ | ||
; | ||
*/; | ||
_proto.onInitialControlTrigger = function onInitialControlTrigger() { | ||
return Promise.resolve(); | ||
} | ||
/** | ||
@@ -353,6 +307,5 @@ * @param {Object} options | ||
* @param {boolean} [options.isEmpty] | ||
*/ | ||
; | ||
*/; | ||
_proto.onZoneShow = function onZoneShow() {} | ||
_proto.onZoneShow = function onZoneShow() {} | ||
/** | ||
@@ -364,6 +317,5 @@ * @param {Object} options | ||
* @param {boolean} [options.isEmpty] | ||
*/ | ||
; | ||
*/; | ||
_proto.onZoneHide = function onZoneHide() {} | ||
_proto.onZoneHide = function onZoneHide() {} | ||
/** | ||
@@ -375,13 +327,8 @@ * @param {Object} options | ||
* @param {boolean} [options.isEmpty] | ||
*/ | ||
; | ||
*/; | ||
_proto.destroy = function destroy() {}; | ||
return Control; | ||
}(); | ||
var ControlResolver = | ||
/*#__PURE__*/ | ||
function () { | ||
var ControlResolver = /*#__PURE__*/function () { | ||
/** | ||
@@ -392,7 +339,5 @@ * @param {Control[]} controls | ||
var _this = this; | ||
if (controls === void 0) { | ||
controls = []; | ||
} | ||
this.zones = []; | ||
@@ -404,9 +349,7 @@ this.controls = []; | ||
} | ||
/** | ||
* @param {Control} control | ||
*/ | ||
var _proto = ControlResolver.prototype; | ||
_proto.addControl = function addControl(control) { | ||
@@ -416,5 +359,5 @@ if (control instanceof Control === false) { | ||
} | ||
this.controls.push(control); | ||
} | ||
/** | ||
@@ -424,12 +367,9 @@ * @param {Zone} zone | ||
* @return {Promise<Control[]>} | ||
*/ | ||
; | ||
*/; | ||
_proto.resolve = function resolve(zone) { | ||
var element = zone.element, | ||
id = zone.id, | ||
isLoaded = zone.isLoaded, | ||
isEmpty = zone.isEmpty, | ||
isInitiallyVisible = zone.isVisible; | ||
id = zone.id, | ||
isLoaded = zone.isLoaded, | ||
isEmpty = zone.isEmpty, | ||
isInitiallyVisible = zone.isVisible; | ||
if (this.zones.some(function (_ref) { | ||
@@ -441,3 +381,2 @@ var existingId = _ref.id; | ||
} | ||
var controlPromises = this.controls.map(function (control) { | ||
@@ -461,3 +400,2 @@ var triggerPromise = memoizePromise({ | ||
} | ||
if (!isControlTriggered) { | ||
@@ -468,3 +406,2 @@ return Promise.reject({ | ||
} | ||
var loadPromise = memoizePromise({ | ||
@@ -484,3 +421,2 @@ key: id, | ||
var isVisible = zone.isVisible; | ||
if (isInitiallyVisible && isVisible) { | ||
@@ -494,3 +430,2 @@ control.onZoneShow({ | ||
} | ||
if (!isInitiallyVisible && !isVisible) { | ||
@@ -504,3 +439,2 @@ control.onZoneHide({ | ||
} | ||
return control; | ||
@@ -511,3 +445,2 @@ })["catch"](function (error) { | ||
} | ||
throw error; | ||
@@ -518,56 +451,52 @@ }); | ||
}; | ||
_proto.destroy = function destroy() { | ||
var _this2 = this; | ||
var triggerPromises = []; | ||
this.controls.forEach(function (control) { | ||
var onInitialControlTriggerCache = control._onInitialControlTriggerCache; | ||
_this2.zones.forEach(function (_ref2) { | ||
var element = _ref2.element, | ||
id = _ref2.id, | ||
isEmpty = _ref2.isEmpty; | ||
var initialControlTriggerResult = onInitialControlTriggerCache[id] || Promise.resolve(); | ||
control.destroy({ | ||
isEmpty: isEmpty, | ||
element: element, | ||
id: id, | ||
initialControlTriggerResult: initialControlTriggerResult | ||
id = _ref2.id, | ||
isEmpty = _ref2.isEmpty; | ||
/* eslint-disable-next-line no-undefined */ | ||
var triggerPromise = Promise.resolve(onInitialControlTriggerCache[id] || undefined).then(function (initialControlTriggerResult) { | ||
control.destroy({ | ||
isEmpty: isEmpty, | ||
element: element, | ||
id: id, | ||
initialControlTriggerResult: initialControlTriggerResult | ||
}); | ||
return; | ||
}); | ||
triggerPromises.push(triggerPromise); | ||
}); | ||
}); | ||
Promise.all(triggerPromises).then(function () { | ||
triggerPromises = null; | ||
return; | ||
}); | ||
this.zones = []; | ||
this.controls = []; | ||
}; | ||
return ControlResolver; | ||
}(); | ||
var Context = | ||
/*#__PURE__*/ | ||
function () { | ||
var Context = /*#__PURE__*/function () { | ||
function Context() { | ||
this._resolveAll = function () {}; | ||
} | ||
/** | ||
* @param {string[]} visibleZoneIds | ||
*/ | ||
var _proto = Context.prototype; | ||
_proto.calculate = function calculate() {}; | ||
_proto.resolve = function resolve() { | ||
this._resolveAll(); | ||
}; | ||
_proto.destroy = function destroy() {}; | ||
return Context; | ||
}(); | ||
var ContextResolver = | ||
/*#__PURE__*/ | ||
function () { | ||
var ContextResolver = /*#__PURE__*/function () { | ||
/** | ||
@@ -579,11 +508,8 @@ * @param {Zones} zones | ||
var _this = this; | ||
if (contexts === void 0) { | ||
contexts = []; | ||
} | ||
if (zones instanceof Zones === false) { | ||
throw new TypeError('Expected zones instance.'); | ||
} | ||
this.zones = zones; | ||
@@ -595,27 +521,21 @@ this.contexts = []; | ||
} | ||
/** | ||
* @param {Context} context | ||
*/ | ||
var _proto = ContextResolver.prototype; | ||
_proto.addContext = function addContext(context) { | ||
var _this2 = this; | ||
if (context instanceof Context === false) { | ||
throw new TypeError('Expected context instance.'); | ||
} | ||
context._resolveAll = function () { | ||
_this2.resolve(); | ||
}; | ||
this.contexts.push(context); | ||
} | ||
/** | ||
* @return {Promise<Array[]>} | ||
*/ | ||
; | ||
*/; | ||
_proto.resolve = function resolve() { | ||
@@ -625,3 +545,2 @@ if (this.zones instanceof Zones === false) { | ||
} | ||
var zoneIds = this.zones.instances.map(function (_ref) { | ||
@@ -631,25 +550,20 @@ var id = _ref.id; | ||
}); | ||
var _this$contexts$reduce = this.contexts.reduce(function (_ref2, context) { | ||
var previouslyHidden = _ref2.hidden, | ||
var previouslyHidden = _ref2.hidden, | ||
previouslyVisible = _ref2.visible; | ||
var _context$calculate = context.calculate(previouslyVisible), | ||
var _context$calculate = context.calculate(previouslyVisible), | ||
nextVisible = _context$calculate.visible, | ||
nextHidden = _context$calculate.hidden; | ||
return { | ||
visible: nextVisible, | ||
hidden: [].concat(previouslyHidden, nextHidden) | ||
}; | ||
}, { | ||
hidden: [], | ||
visible: zoneIds | ||
}), | ||
hidden = _this$contexts$reduce.hidden, | ||
visible = _this$contexts$reduce.visible; | ||
return { | ||
visible: nextVisible, | ||
hidden: [].concat(previouslyHidden, nextHidden) | ||
}; | ||
}, { | ||
hidden: [], | ||
visible: zoneIds | ||
}), | ||
hidden = _this$contexts$reduce.hidden, | ||
visible = _this$contexts$reduce.visible; | ||
return Promise.all([this.zones.hide(hidden), this.zones.show(visible), this.zones.write(visible)]); | ||
}; | ||
_proto.destroy = function destroy() { | ||
@@ -662,13 +576,8 @@ this.contexts.forEach(function (context) { | ||
}; | ||
return ContextResolver; | ||
}(); | ||
var Service = | ||
/*#__PURE__*/ | ||
function () { | ||
var Service = /*#__PURE__*/function () { | ||
function Service() {} | ||
var _proto = Service.prototype; | ||
/** | ||
@@ -679,2 +588,3 @@ * @param {HTMLElement} element | ||
_proto.afterZoneRegistered = function afterZoneRegistered() {} | ||
/** | ||
@@ -684,6 +594,5 @@ * @param {Object[]} zones | ||
* @param {string} zones[].id | ||
*/ | ||
; | ||
*/; | ||
_proto.beforeWriteZones = function beforeWriteZones() {} | ||
_proto.beforeWriteZones = function beforeWriteZones() {} | ||
/** | ||
@@ -694,5 +603,3 @@ * @param {HTMLElement} element | ||
* @return {Promise<Boolean>} | ||
*/ | ||
; | ||
*/; | ||
_proto.writeZone = function writeZone() { | ||
@@ -703,2 +610,3 @@ // If true, zone has content | ||
} | ||
/** | ||
@@ -708,15 +616,9 @@ * @param {Object[]} zones | ||
* @param {string} zones[].id | ||
*/ | ||
; | ||
*/; | ||
_proto.afterWriteZones = function afterWriteZones() {}; | ||
_proto.destroy = function destroy() {}; | ||
return Service; | ||
}(); | ||
var Advertol = | ||
/*#__PURE__*/ | ||
function () { | ||
var Advertol = /*#__PURE__*/function () { | ||
/** | ||
@@ -733,20 +635,17 @@ * @param {Object} options | ||
} | ||
var _options = options, | ||
_options$zones = _options.zones, | ||
zones = _options$zones === void 0 ? [] : _options$zones, | ||
_options$service = _options.service, | ||
service = _options$service === void 0 ? null : _options$service, | ||
_options$control = _options.control, | ||
control = _options$control === void 0 ? [] : _options$control, | ||
_options$context = _options.context, | ||
context = _options$context === void 0 ? [] : _options$context; | ||
_options$zones = _options.zones, | ||
zones = _options$zones === void 0 ? [] : _options$zones, | ||
_options$service = _options.service, | ||
service = _options$service === void 0 ? null : _options$service, | ||
_options$control = _options.control, | ||
control = _options$control === void 0 ? [] : _options$control, | ||
_options$context = _options.context, | ||
context = _options$context === void 0 ? [] : _options$context; | ||
if (service instanceof Service === false) { | ||
throw new TypeError('Expected a service.'); | ||
} | ||
var zonesInstances = zones.map(function (_ref) { | ||
var element = _ref.element, | ||
id = _ref.id; | ||
id = _ref.id; | ||
return new Zone(id, element); | ||
@@ -759,9 +658,7 @@ }); | ||
} | ||
/** | ||
* @return {Promise} | ||
*/ | ||
var _proto = Advertol.prototype; | ||
_proto.resolve = function resolve() { | ||
@@ -772,18 +669,17 @@ return this.contextResolver.resolve().then(function () { | ||
} | ||
/** | ||
* @param {Control} control | ||
*/ | ||
; | ||
*/; | ||
_proto.addControl = function addControl(control) { | ||
this.controlResolver.addControl(control); | ||
} | ||
/** | ||
* @param {Context} context | ||
*/ | ||
; | ||
*/; | ||
_proto.addContext = function addContext(context) { | ||
this.contextResolver.addContext(context); | ||
} | ||
/** | ||
@@ -793,11 +689,8 @@ * @param {Object} zone | ||
* @param {string} zone.id | ||
*/ | ||
; | ||
*/; | ||
_proto.addZone = function addZone(_ref2) { | ||
var element = _ref2.element, | ||
id = _ref2.id; | ||
id = _ref2.id; | ||
this.zones.add(new Zone(id, element)); | ||
}; | ||
_proto.destroy = function destroy() { | ||
@@ -809,3 +702,2 @@ this.service.destroy(); | ||
}; | ||
return Advertol; | ||
@@ -818,4 +710,2 @@ }(); | ||
*/ | ||
var index = (function (options) { | ||
@@ -825,7 +715,5 @@ if (options === void 0) { | ||
} | ||
var instance = new Advertol(options); | ||
return ['resolve', 'addControl', 'addContext', 'addZone', 'destroy'].reduce(function (obj, method) { | ||
var _extends2; | ||
return _extends({}, obj, (_extends2 = {}, _extends2[method] = instance[method].bind(instance), _extends2)); | ||
@@ -835,5 +723,6 @@ }, {}); | ||
exports.default = index; | ||
exports.Context = Context; | ||
exports.Control = Control; | ||
exports.Context = Context; | ||
exports.Service = Service; | ||
exports.default = index; | ||
//# sourceMappingURL=index.cjs.js.map |
301
index.esm.js
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
@@ -12,12 +11,8 @@ if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
var Zone = | ||
/*#__PURE__*/ | ||
function () { | ||
var Zone = /*#__PURE__*/function () { | ||
/** | ||
@@ -31,7 +26,5 @@ * @param {string} id | ||
} | ||
if (element instanceof HTMLElement === false) { | ||
throw new TypeError('Expected an element.'); | ||
} | ||
this.id = id; | ||
@@ -43,13 +36,9 @@ this.element = element; | ||
} | ||
var _proto = Zone.prototype; | ||
_proto.show = function show() { | ||
this.isVisible = true; | ||
}; | ||
_proto.hide = function hide() { | ||
this.isVisible = false; | ||
}; | ||
_proto.setAsLoaded = function setAsLoaded() { | ||
@@ -59,3 +48,2 @@ this.isLoaded = true; | ||
}; | ||
_proto.setAsEmpty = function setAsEmpty() { | ||
@@ -65,7 +53,5 @@ this.isLoaded = true; | ||
}; | ||
_proto.destroy = function destroy() { | ||
this.isVisible = false; | ||
}; | ||
return Zone; | ||
@@ -76,9 +62,7 @@ }(); | ||
var key = _ref.key, | ||
cache = _ref.cache, | ||
result = _ref.result; | ||
cache = _ref.cache, | ||
result = _ref.result; | ||
if (cache[key] instanceof Promise) { | ||
return cache[key]; | ||
} | ||
cache[key] = result(); | ||
@@ -93,3 +77,2 @@ return cache[key]; | ||
*/ | ||
function filterById(zoneIds) { | ||
@@ -106,6 +89,3 @@ /** | ||
} | ||
var Zones = | ||
/*#__PURE__*/ | ||
function () { | ||
var Zones = /*#__PURE__*/function () { | ||
/** | ||
@@ -118,3 +98,2 @@ * @param {Zone[]} zones | ||
var _this = this; | ||
this.instances = []; | ||
@@ -128,9 +107,7 @@ this.writeResults = {}; | ||
} | ||
/** | ||
* @param {Zone} zone | ||
*/ | ||
var _proto = Zones.prototype; | ||
_proto.add = function add(zone) { | ||
@@ -140,6 +117,4 @@ if (zone instanceof Zone === false) { | ||
} | ||
var element = zone.element, | ||
id = zone.id; | ||
id = zone.id; | ||
if (this.instances.some(function (_ref2) { | ||
@@ -151,3 +126,2 @@ var existingId = _ref2.id; | ||
} | ||
this.instances.push(zone); | ||
@@ -159,2 +133,3 @@ this.service.afterZoneRegistered({ | ||
} | ||
/** | ||
@@ -164,8 +139,5 @@ * @param {string[]} zoneIds | ||
* @return {Promise<Zone[]>} | ||
*/ | ||
; | ||
*/; | ||
_proto.show = function show(zoneIds) { | ||
var _this2 = this; | ||
var boundFilterById = filterById(zoneIds); | ||
@@ -179,7 +151,5 @@ var zones = this.instances.filter(boundFilterById); | ||
zone.show(); | ||
if (isInitiallyVisible) { | ||
return Promise.resolve(zone); | ||
} | ||
return _this2.controlResolver.resolve(zone).then(function () { | ||
@@ -191,2 +161,3 @@ return zone; | ||
} | ||
/** | ||
@@ -196,8 +167,5 @@ * @param {string[]} zoneIds | ||
* @return {Promise<Zone[]>} | ||
*/ | ||
; | ||
*/; | ||
_proto.hide = function hide(zoneIds) { | ||
var _this3 = this; | ||
var boundFilterById = filterById(zoneIds); | ||
@@ -211,7 +179,5 @@ var zones = this.instances.filter(boundFilterById); | ||
zone.hide(); | ||
if (!isInitiallyVisible) { | ||
return Promise.resolve(zone); | ||
} | ||
return _this3.controlResolver.resolve(zone).then(function () { | ||
@@ -223,2 +189,3 @@ return zone; | ||
} | ||
/** | ||
@@ -228,8 +195,5 @@ * @param {string[]} zoneIds | ||
* @return {Promise<Zone[]>} | ||
*/ | ||
; | ||
*/; | ||
_proto.write = function write(zoneIds) { | ||
var _this4 = this; | ||
var boundFilterById = filterById(zoneIds); | ||
@@ -242,3 +206,3 @@ var zones = this.instances.filter(boundFilterById).filter(function (_ref5) { | ||
var element = _ref6.element, | ||
id = _ref6.id; | ||
id = _ref6.id; | ||
return { | ||
@@ -252,3 +216,3 @@ element: element, | ||
var element = zone.element, | ||
id = zone.id; | ||
id = zone.id; | ||
var writePromise = memoizePromise({ | ||
@@ -266,3 +230,2 @@ key: id, | ||
var isEmpty = !hasContent; | ||
if (isEmpty) { | ||
@@ -273,10 +236,7 @@ zone.setAsEmpty(); | ||
} | ||
var isInitiallyVisible = zone.isVisible; | ||
zone.show(); | ||
if (isInitiallyVisible) { | ||
return Promise.resolve(zone); | ||
} | ||
return _this4.controlResolver.resolve(zone).then(function () { | ||
@@ -291,3 +251,2 @@ return zone; | ||
}; | ||
_proto.destroy = function destroy() { | ||
@@ -299,9 +258,6 @@ this.instances.forEach(function (zone) { | ||
}; | ||
return Zones; | ||
}(); | ||
var Control = | ||
/*#__PURE__*/ | ||
function () { | ||
var Control = /*#__PURE__*/function () { | ||
function Control() { | ||
@@ -311,2 +267,3 @@ this._shouldTriggerControlCache = {}; | ||
} | ||
/** | ||
@@ -320,9 +277,7 @@ * @param {Object} options | ||
*/ | ||
var _proto = Control.prototype; | ||
_proto.shouldTriggerControl = function shouldTriggerControl() { | ||
return Promise.resolve(false); | ||
} | ||
/** | ||
@@ -335,8 +290,7 @@ * @param {Object} options | ||
* @return {Promise<*>} | ||
*/ | ||
; | ||
*/; | ||
_proto.onInitialControlTrigger = function onInitialControlTrigger() { | ||
return Promise.resolve(); | ||
} | ||
/** | ||
@@ -348,6 +302,5 @@ * @param {Object} options | ||
* @param {boolean} [options.isEmpty] | ||
*/ | ||
; | ||
*/; | ||
_proto.onZoneShow = function onZoneShow() {} | ||
_proto.onZoneShow = function onZoneShow() {} | ||
/** | ||
@@ -359,6 +312,5 @@ * @param {Object} options | ||
* @param {boolean} [options.isEmpty] | ||
*/ | ||
; | ||
*/; | ||
_proto.onZoneHide = function onZoneHide() {} | ||
_proto.onZoneHide = function onZoneHide() {} | ||
/** | ||
@@ -370,13 +322,8 @@ * @param {Object} options | ||
* @param {boolean} [options.isEmpty] | ||
*/ | ||
; | ||
*/; | ||
_proto.destroy = function destroy() {}; | ||
return Control; | ||
}(); | ||
var ControlResolver = | ||
/*#__PURE__*/ | ||
function () { | ||
var ControlResolver = /*#__PURE__*/function () { | ||
/** | ||
@@ -387,7 +334,5 @@ * @param {Control[]} controls | ||
var _this = this; | ||
if (controls === void 0) { | ||
controls = []; | ||
} | ||
this.zones = []; | ||
@@ -399,9 +344,7 @@ this.controls = []; | ||
} | ||
/** | ||
* @param {Control} control | ||
*/ | ||
var _proto = ControlResolver.prototype; | ||
_proto.addControl = function addControl(control) { | ||
@@ -411,5 +354,5 @@ if (control instanceof Control === false) { | ||
} | ||
this.controls.push(control); | ||
} | ||
/** | ||
@@ -419,12 +362,9 @@ * @param {Zone} zone | ||
* @return {Promise<Control[]>} | ||
*/ | ||
; | ||
*/; | ||
_proto.resolve = function resolve(zone) { | ||
var element = zone.element, | ||
id = zone.id, | ||
isLoaded = zone.isLoaded, | ||
isEmpty = zone.isEmpty, | ||
isInitiallyVisible = zone.isVisible; | ||
id = zone.id, | ||
isLoaded = zone.isLoaded, | ||
isEmpty = zone.isEmpty, | ||
isInitiallyVisible = zone.isVisible; | ||
if (this.zones.some(function (_ref) { | ||
@@ -436,3 +376,2 @@ var existingId = _ref.id; | ||
} | ||
var controlPromises = this.controls.map(function (control) { | ||
@@ -456,3 +395,2 @@ var triggerPromise = memoizePromise({ | ||
} | ||
if (!isControlTriggered) { | ||
@@ -463,3 +401,2 @@ return Promise.reject({ | ||
} | ||
var loadPromise = memoizePromise({ | ||
@@ -479,3 +416,2 @@ key: id, | ||
var isVisible = zone.isVisible; | ||
if (isInitiallyVisible && isVisible) { | ||
@@ -489,3 +425,2 @@ control.onZoneShow({ | ||
} | ||
if (!isInitiallyVisible && !isVisible) { | ||
@@ -499,3 +434,2 @@ control.onZoneHide({ | ||
} | ||
return control; | ||
@@ -506,3 +440,2 @@ })["catch"](function (error) { | ||
} | ||
throw error; | ||
@@ -513,56 +446,52 @@ }); | ||
}; | ||
_proto.destroy = function destroy() { | ||
var _this2 = this; | ||
var triggerPromises = []; | ||
this.controls.forEach(function (control) { | ||
var onInitialControlTriggerCache = control._onInitialControlTriggerCache; | ||
_this2.zones.forEach(function (_ref2) { | ||
var element = _ref2.element, | ||
id = _ref2.id, | ||
isEmpty = _ref2.isEmpty; | ||
var initialControlTriggerResult = onInitialControlTriggerCache[id] || Promise.resolve(); | ||
control.destroy({ | ||
isEmpty: isEmpty, | ||
element: element, | ||
id: id, | ||
initialControlTriggerResult: initialControlTriggerResult | ||
id = _ref2.id, | ||
isEmpty = _ref2.isEmpty; | ||
/* eslint-disable-next-line no-undefined */ | ||
var triggerPromise = Promise.resolve(onInitialControlTriggerCache[id] || undefined).then(function (initialControlTriggerResult) { | ||
control.destroy({ | ||
isEmpty: isEmpty, | ||
element: element, | ||
id: id, | ||
initialControlTriggerResult: initialControlTriggerResult | ||
}); | ||
return; | ||
}); | ||
triggerPromises.push(triggerPromise); | ||
}); | ||
}); | ||
Promise.all(triggerPromises).then(function () { | ||
triggerPromises = null; | ||
return; | ||
}); | ||
this.zones = []; | ||
this.controls = []; | ||
}; | ||
return ControlResolver; | ||
}(); | ||
var Context = | ||
/*#__PURE__*/ | ||
function () { | ||
var Context = /*#__PURE__*/function () { | ||
function Context() { | ||
this._resolveAll = function () {}; | ||
} | ||
/** | ||
* @param {string[]} visibleZoneIds | ||
*/ | ||
var _proto = Context.prototype; | ||
_proto.calculate = function calculate() {}; | ||
_proto.resolve = function resolve() { | ||
this._resolveAll(); | ||
}; | ||
_proto.destroy = function destroy() {}; | ||
return Context; | ||
}(); | ||
var ContextResolver = | ||
/*#__PURE__*/ | ||
function () { | ||
var ContextResolver = /*#__PURE__*/function () { | ||
/** | ||
@@ -574,11 +503,8 @@ * @param {Zones} zones | ||
var _this = this; | ||
if (contexts === void 0) { | ||
contexts = []; | ||
} | ||
if (zones instanceof Zones === false) { | ||
throw new TypeError('Expected zones instance.'); | ||
} | ||
this.zones = zones; | ||
@@ -590,27 +516,21 @@ this.contexts = []; | ||
} | ||
/** | ||
* @param {Context} context | ||
*/ | ||
var _proto = ContextResolver.prototype; | ||
_proto.addContext = function addContext(context) { | ||
var _this2 = this; | ||
if (context instanceof Context === false) { | ||
throw new TypeError('Expected context instance.'); | ||
} | ||
context._resolveAll = function () { | ||
_this2.resolve(); | ||
}; | ||
this.contexts.push(context); | ||
} | ||
/** | ||
* @return {Promise<Array[]>} | ||
*/ | ||
; | ||
*/; | ||
_proto.resolve = function resolve() { | ||
@@ -620,3 +540,2 @@ if (this.zones instanceof Zones === false) { | ||
} | ||
var zoneIds = this.zones.instances.map(function (_ref) { | ||
@@ -626,25 +545,20 @@ var id = _ref.id; | ||
}); | ||
var _this$contexts$reduce = this.contexts.reduce(function (_ref2, context) { | ||
var previouslyHidden = _ref2.hidden, | ||
var previouslyHidden = _ref2.hidden, | ||
previouslyVisible = _ref2.visible; | ||
var _context$calculate = context.calculate(previouslyVisible), | ||
var _context$calculate = context.calculate(previouslyVisible), | ||
nextVisible = _context$calculate.visible, | ||
nextHidden = _context$calculate.hidden; | ||
return { | ||
visible: nextVisible, | ||
hidden: [].concat(previouslyHidden, nextHidden) | ||
}; | ||
}, { | ||
hidden: [], | ||
visible: zoneIds | ||
}), | ||
hidden = _this$contexts$reduce.hidden, | ||
visible = _this$contexts$reduce.visible; | ||
return { | ||
visible: nextVisible, | ||
hidden: [].concat(previouslyHidden, nextHidden) | ||
}; | ||
}, { | ||
hidden: [], | ||
visible: zoneIds | ||
}), | ||
hidden = _this$contexts$reduce.hidden, | ||
visible = _this$contexts$reduce.visible; | ||
return Promise.all([this.zones.hide(hidden), this.zones.show(visible), this.zones.write(visible)]); | ||
}; | ||
_proto.destroy = function destroy() { | ||
@@ -657,13 +571,8 @@ this.contexts.forEach(function (context) { | ||
}; | ||
return ContextResolver; | ||
}(); | ||
var Service = | ||
/*#__PURE__*/ | ||
function () { | ||
var Service = /*#__PURE__*/function () { | ||
function Service() {} | ||
var _proto = Service.prototype; | ||
/** | ||
@@ -674,2 +583,3 @@ * @param {HTMLElement} element | ||
_proto.afterZoneRegistered = function afterZoneRegistered() {} | ||
/** | ||
@@ -679,6 +589,5 @@ * @param {Object[]} zones | ||
* @param {string} zones[].id | ||
*/ | ||
; | ||
*/; | ||
_proto.beforeWriteZones = function beforeWriteZones() {} | ||
_proto.beforeWriteZones = function beforeWriteZones() {} | ||
/** | ||
@@ -689,5 +598,3 @@ * @param {HTMLElement} element | ||
* @return {Promise<Boolean>} | ||
*/ | ||
; | ||
*/; | ||
_proto.writeZone = function writeZone() { | ||
@@ -698,2 +605,3 @@ // If true, zone has content | ||
} | ||
/** | ||
@@ -703,15 +611,9 @@ * @param {Object[]} zones | ||
* @param {string} zones[].id | ||
*/ | ||
; | ||
*/; | ||
_proto.afterWriteZones = function afterWriteZones() {}; | ||
_proto.destroy = function destroy() {}; | ||
return Service; | ||
}(); | ||
var Advertol = | ||
/*#__PURE__*/ | ||
function () { | ||
var Advertol = /*#__PURE__*/function () { | ||
/** | ||
@@ -728,20 +630,17 @@ * @param {Object} options | ||
} | ||
var _options = options, | ||
_options$zones = _options.zones, | ||
zones = _options$zones === void 0 ? [] : _options$zones, | ||
_options$service = _options.service, | ||
service = _options$service === void 0 ? null : _options$service, | ||
_options$control = _options.control, | ||
control = _options$control === void 0 ? [] : _options$control, | ||
_options$context = _options.context, | ||
context = _options$context === void 0 ? [] : _options$context; | ||
_options$zones = _options.zones, | ||
zones = _options$zones === void 0 ? [] : _options$zones, | ||
_options$service = _options.service, | ||
service = _options$service === void 0 ? null : _options$service, | ||
_options$control = _options.control, | ||
control = _options$control === void 0 ? [] : _options$control, | ||
_options$context = _options.context, | ||
context = _options$context === void 0 ? [] : _options$context; | ||
if (service instanceof Service === false) { | ||
throw new TypeError('Expected a service.'); | ||
} | ||
var zonesInstances = zones.map(function (_ref) { | ||
var element = _ref.element, | ||
id = _ref.id; | ||
id = _ref.id; | ||
return new Zone(id, element); | ||
@@ -754,9 +653,7 @@ }); | ||
} | ||
/** | ||
* @return {Promise} | ||
*/ | ||
var _proto = Advertol.prototype; | ||
_proto.resolve = function resolve() { | ||
@@ -767,18 +664,17 @@ return this.contextResolver.resolve().then(function () { | ||
} | ||
/** | ||
* @param {Control} control | ||
*/ | ||
; | ||
*/; | ||
_proto.addControl = function addControl(control) { | ||
this.controlResolver.addControl(control); | ||
} | ||
/** | ||
* @param {Context} context | ||
*/ | ||
; | ||
*/; | ||
_proto.addContext = function addContext(context) { | ||
this.contextResolver.addContext(context); | ||
} | ||
/** | ||
@@ -788,11 +684,8 @@ * @param {Object} zone | ||
* @param {string} zone.id | ||
*/ | ||
; | ||
*/; | ||
_proto.addZone = function addZone(_ref2) { | ||
var element = _ref2.element, | ||
id = _ref2.id; | ||
id = _ref2.id; | ||
this.zones.add(new Zone(id, element)); | ||
}; | ||
_proto.destroy = function destroy() { | ||
@@ -804,3 +697,2 @@ this.service.destroy(); | ||
}; | ||
return Advertol; | ||
@@ -813,4 +705,2 @@ }(); | ||
*/ | ||
var index = (function (options) { | ||
@@ -820,7 +710,5 @@ if (options === void 0) { | ||
} | ||
var instance = new Advertol(options); | ||
return ['resolve', 'addControl', 'addContext', 'addZone', 'destroy'].reduce(function (obj, method) { | ||
var _extends2; | ||
return _extends({}, obj, (_extends2 = {}, _extends2[method] = instance[method].bind(instance), _extends2)); | ||
@@ -831,2 +719,3 @@ }, {}); | ||
export default index; | ||
export { Control, Context, Service }; | ||
export { Context, Control, Service }; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@advertol/core", | ||
"version": "1.0.1-alpha.0", | ||
"version": "1.0.1", | ||
"description": "Advertisement zones manager.", | ||
@@ -10,4 +10,5 @@ "main": "index.cjs.js", | ||
"files": [ | ||
"index.cjs.js", | ||
"index.esm.js", | ||
"index.cjs.{js,js.map}", | ||
"index.esm.{js,js.map}", | ||
"CHANGELOG.md", | ||
"LICENSE.md", | ||
@@ -23,2 +24,3 @@ "README.md" | ||
"lint": "eslint '{index,lib/**/*,test/**/*}.js'", | ||
"postpublish": "GITHUB_TOKEN=$GITHUB_RELEASE_TOKEN github-release-from-changelog", | ||
"prepublishOnly": "npm run build", | ||
@@ -28,3 +30,4 @@ "release": "np", | ||
"test:automated": "BABEL_ENV=test karma start", | ||
"test:automated:watch": "npm run test:automated -- --auto-watch --no-single-run" | ||
"test:automated:watch": "npm run test:automated -- --auto-watch --no-single-run", | ||
"version": "version-changelog CHANGELOG.md && changelog-verify CHANGELOG.md && git add CHANGELOG.md" | ||
}, | ||
@@ -39,2 +42,4 @@ "devDependencies": { | ||
"babel-preset-niksy": "^4.1.0", | ||
"changelog-verify": "^1.1.2", | ||
"core-js": "^2.6.5", | ||
"eslint": "^5.4.0", | ||
@@ -49,6 +54,7 @@ "eslint-config-niksy": "^6.1.0", | ||
"esm": "^3.0.51", | ||
"github-release-from-changelog": "^1.3.2", | ||
"istanbul-instrumenter-loader": "^3.0.1", | ||
"karma": "^1.1.0", | ||
"karma": "^4.0.1", | ||
"karma-browserstack-launcher": "^1.0.0", | ||
"karma-chrome-launcher": "^1.0.1", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-coverage-istanbul-reporter": "^2.0.1", | ||
@@ -60,8 +66,9 @@ "karma-fixture": "^0.2.6", | ||
"karma-sourcemap-loader": "^0.3.7", | ||
"karma-webpack": "^3.0.0", | ||
"karma-webpack": "^4.0.2", | ||
"mocha": "^4.1.0", | ||
"np": "^3.0.4", | ||
"np": "^4.0.2", | ||
"rollup": "^1.0.0", | ||
"rollup-plugin-babel": "^4.2.0", | ||
"sinon": "^2.4.1", | ||
"version-changelog": "^3.1.1", | ||
"webpack": "^4.12.0" | ||
@@ -82,9 +89,8 @@ }, | ||
"type": "git", | ||
"url": "git+https://github.com/niksy/advertol.git" | ||
"url": "git+https://github.com/niksy/advertol-core.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/niksy/advertol/issues" | ||
"url": "https://github.com/niksy/advertol-core/issues" | ||
}, | ||
"homepage": "https://github.com/niksy/advertol#readme", | ||
"gitHead": "37c1884afb062b799450a8a7e808910ebd8e88c0" | ||
"homepage": "https://github.com/niksy/advertol-core#readme" | ||
} |
@@ -122,8 +122,8 @@ # @advertol/core | ||
[ci]: https://travis-ci.com/niksy/advertol | ||
[ci-img]: https://travis-ci.com/niksy/advertol.svg?branch=master | ||
[ci]: https://travis-ci.com/niksy/advertol-core | ||
[ci-img]: https://travis-ci.com/niksy/advertol-core.svg?branch=master | ||
[browserstack]: https://www.browserstack.com/ | ||
[browserstack-img]: https://www.browserstack.com/automate/badge.svg?badge_key=MXdvSXc0TVVSUG1lQWlCV25Sc0xlTlYvRTdzaFVNM09JRXNXYStGSytQND0tLUs4OUVYWkFEY3JNZDJmMlBIeTdnV0E9PQ==--f371818440411f6e9a295345dc5ee488fce79ce1 | ||
[browserstack-img]: https://www.browserstack.com/automate/badge.svg?badge_key=YWxaem45M0tCRHNpTkdZdHdlcGx4WDg4eVB1RUlqUy8wWk5kSFowQXJrcz0tLURaMU5NcUJMOERDQ1pnNkZwcTM3bGc9PQ==--761e47cbb39133df6ee49bbb87b2f53c6c5ef579 | ||
[service]: https://github.com/niksy/advertol/docs/service.md | ||
[control]: https://github.com/niksy/advertol/docs/control.md | ||
[context]: https://github.com/niksy/advertol/docs/context.md |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
104213
8
0
37
1260