UNPKG

gluebert

Version:

gluebert.js is a tiny helper orchestrating interactive html elements with on demand dynamic import Edit

1 lines 2.6 kB
'use strict';Object.defineProperty(exports,'__esModule',{value:!0}),exports.Gluebert=void 0;var _typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&'function'==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?'symbol':typeof a},_createClass=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,'value'in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),_module=require('./module/module.launcher'),_data=require('./data/data.observer'),_data2=require('./data/data.manager'),_element=require('./element/element.builder'),_polyfill=require('./polyfills/polyfill.service');function _toConsumableArray(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}return Array.from(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}var DEFAULT_OPTIONS={elementReadyClass:'gb-ready',elementSleepingClass:'gb-sleep',elementLoadingClass:'gb-loading'},Gluebert=function(){function a(b){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};_classCallCheck(this,a),this._options=Object.assign({},DEFAULT_OPTIONS,d),this._modules=b instanceof Array?b:null,this._elements=this._modules?this._extractElements(b):null,this._data=c instanceof Array?c:null,this._schemaValidator=null,this._templateEngine=null,this._polyfillService=new _polyfill.Polyfill}return _createClass(a,[{key:'start',value:function start(){var a=this;return this._polyfillService.fill().then(function(){a._init()}),this}},{key:'_init',value:function _init(){this.elementBuilder=new _element.ElementBuilder(this._elements,this._templateEngine,this._schemaValidator,this._options),this.dataObserver=new _data.DataObserver,this.dataManager=new _data2.DataManager(this.dataObserver,this._data),this.moduleLauncher=new _module.ModuleLauncher(this._modules,this.dataObserver,this.elementBuilder)}},{key:'_extractElements',value:function _extractElements(a){return a.reduce(function(c,a){var b=a.getElementSignatures();return b.size&&c.push.apply(c,_toConsumableArray(b)),c},[])}},{key:'setSchemaValidator',value:function setSchemaValidator(a){return'function'===a&&(this._schemaValidator=a),this}},{key:'setTemplateEngine',value:function setTemplateEngine(a){return'object'===('undefined'==typeof a?'undefined':_typeof(a))&&(this._templateEngine=a),this}}]),a}();exports.Gluebert=Gluebert;