(function() {
/**
* @namespace service
* @memberof Help4
*/
Help4.service = {};
const SUPER = Help4.Object.prototype;
/**
* @typedef {Object} Help4.service.Service.Params
* @property {Help4.controller.Controller} controller
* @property {Help4.EventBus} eventBus
*/
/**
* Service base class.
* @constructor
* @param {Help4.service.Service.Params} [params]
* @param {Object} [classParams = null]
*/
Help4.service.Service = function(params, classParams = null) {
if (classParams) this._params = classParams;
this._params = Help4.extendObject(this._params || {}, {
controller: null,
eventBus: null
}, false);
Help4.Object.call(this, params);
this._observers = {};
this._controls = {};
};
Help4.service.Service.prototype = Object.create(SUPER);
Help4.service.Service.prototype.constructor = Help4.service.Service;
Help4.extendObject(Help4.service.Service.prototype, {
destroy: _destroy,
setParams: _setParams,
getController: function() { return this._params.controller; }
});
function _destroy() {
SUPER.destroy.call(this);
const map = ['_observers', '_controls'];
for (let i = 0, key; key = map[i++];) {
if (!this[key]) continue;
for (let j in this[key]) {
if (this[key].hasOwnProperty(j)) {
this[key][j].destroy();
this[key][j] = null;
}
}
this[key] = null;
}
}
function _setParams(params) {
const p = this._params;
for (let i in params) {
if (params.hasOwnProperty(i) && p.hasOwnProperty(i)) {
p[i] = params[i];
}
}
}
})();