@veams/base
Version:
Base Class for Components and Services
90 lines • 2.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Represents a base constructor which supports
* options merging and
* saving of standard stuff.
*
* @module Base
* @author Sebastian Fitzner
*/
/**
* Imports
*/
var mergeHelper = require("deepmerge");
var mixin_1 = require("@veams/helpers/lib/function/mixin");
var make_id_1 = require("@veams/helpers/lib/utility/make-id");
// Workaround for browserify and webpack bundling
var merge = mergeHelper.default || mergeHelper;
var Base = /** @class */ (function () {
/**
* Constructor
*
* to save standard elements like el and options and
* execute initialize as default method.
*
* @param {Object} BaseConfig - See interface.
* @param {String} BaseConfig.namespace - Add custom namespace to your class.
* @param {Object} BaseConfig.el - Save element in class.
* @param {Object} BaseConfig.options - Options passed by init process.
* @param {Object} opts [{}] - Object which contains options of the extended class.
*/
function Base(_a, opts) {
var namespace = _a.namespace, el = _a.el, options = _a.options;
if (opts === void 0) { opts = {}; }
this.namespace = namespace || 'base';
this.instanceId = this.namespace;
this.options = opts;
this._options = options;
this.mixin = mixin_1.default;
if (el) {
this.el = el;
}
}
Object.defineProperty(Base.prototype, "namespace", {
get: function () {
return this._namespace;
},
// ----------------------------------------------------------
// GETTER & SETTERS
// ----------------------------------------------------------
set: function (namespace) {
this._namespace = namespace;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Base.prototype, "instanceId", {
get: function () {
return this._instanceId;
},
set: function (id) {
this._instanceId = id + "_" + Date.now() + '_' + make_id_1.default();
},
enumerable: true,
configurable: true
});
Object.defineProperty(Base.prototype, "_options", {
get: function () {
return this.options;
},
set: function (options) {
this.options = merge(this.options, options || {});
},
enumerable: true,
configurable: true
});
Object.defineProperty(Base.prototype, "el", {
get: function () {
return this._el;
},
set: function (element) {
this._el = element;
},
enumerable: true,
configurable: true
});
return Base;
}());
exports.default = Base;
//# sourceMappingURL=index.js.map