gluebert
Version:
gluebert.js is a tiny helper orchestrating interactive html elements with on demand dynamic import Edit
1 lines • 2.38 kB
JavaScript
;var _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}}();Object.defineProperty(exports,'__esModule',{value:!0});function _asyncToGenerator(a){return function(){var b=a.apply(this,arguments);return new Promise(function(a,c){function d(e,f){try{var g=b[e](f),h=g.value}catch(a){return void c(a)}return g.done?void a(h):Promise.resolve(h).then(function(a){d('next',a)},function(a){d('throw',a)})}return d('next')})}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}var DependencyManager=function(){function a(){_classCallCheck(this,a),this._dependencies={},this._resolvedDependencies={},this._scope=null}return _createClass(a,[{key:'isValid',value:function isValid(a,b){return'string'==typeof a&&'function'==typeof b}},{key:'add',value:function add(a,b){return this.isValid(a,b)&&(this._dependencies[a]=b),this}},{key:'resolve',value:function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(){var b,c,d=this;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return b=Object.keys(this._dependencies),a.next=3,Promise.all(b.map(function(a){return d._dependencies[a]()}));case 3:return c=a.sent,b.forEach(function(a,b){d._resolvedDependencies[a]=c[b]}),a.abrupt('return',this);case 6:case'end':return a.stop();}},a,this)}));return function resolve(){return a.apply(this,arguments)}}()},{key:'hasDependencies',value:function hasDependencies(){return!!Object.keys(this._dependencies).length}},{key:'inject',value:function inject(a){var b=this;return a&&this.hasDependencies()&&(this._scope=a,Object.keys(this._resolvedDependencies).forEach(function(c){var d=b._resolvedDependencies[c];if('string'==typeof c&&'undefined'==typeof a[c])a[c]=d;else if('string'==typeof c)throw new Error('\n Could not bind dependency \''+c+'\' property alread reserved by controller.\n We recommend to work with a prefix convention like all dependencies have a $ sign prefixed\n and become accessible by this.$dependencyKey.\n ')})),this}}]),a}();exports.DependencyManager=DependencyManager;