@excellens/elementary
Version:
A custom element library in plain javascript (almost).
4 lines (3 loc) • 3.55 kB
JavaScript
/*! @excellens/elementary 1.0.0 https://github.com/Excellens/elementary#readme @license MIT */
var Elementary=function(t){"use strict";function i(t,i,n){for(const e in t)(n||t.hasOwnProperty(e))&&i(e,t[e])}function n(t,n){return i(t,(function(t,i){n[t]="function"==typeof i?i.bind(n):i}),!0),n}var e=Object.freeze({__proto__:null,Visit:i,Merge:n});function s(t){return this.list=t||[],this.add=function(t,i){return void 0===i&&(i=t,t=this.list.length),this.set(t,i)},this.remove=function(t,i){return void 0===i&&(i=t,t=this.list.indexOf(i,0)),this.list.splice(t,1),this},this.get=function(t){return this.has(t)?this.list[t]:null},this.set=function(t,i){return this.list[t]=i,this},this.has=function(t){return void 0!==this.list[t]},this.each=function(t){for(let i=0,n=this.list.length;i<n;i++)t(this.list[i],i);return this},this.push=function(t){return this.list[this.list.length]=t,this},this.pop=function(){const t=this.list.length-1;if(0>t)return null;const i=this.list[t];return this.list.length=t,i},this.size=function(){return this.list.length},this.clear=function(){return this.list.length=0,this},n(this,{})}var r=Object.freeze({__proto__:null,Collection:s,CollectionMap:function(t){return this.list=t||{},this.add=function(t,i){return this.set(t,i)},this.remove=function(t){return this.list.hasOwnProperty(t)&&delete this.list[t],this},this.get=function(t){return this.has(t)?this.list[t]:null},this.set=function(t,i){return this.list[t]=i,this},this.has=function(t,i){return void 0===i&&(i=!0),i?this.list.hasOwnProperty(t):t in this.list},this.each=function(t){for(let i in this.list)this.list.hasOwnProperty(i)&&t(this.list[i],i);return this},this.clear=function(){for(let t in this.list)this.list.hasOwnProperty(t)&&delete this.list[t];return this},n(this,{})}});function h(t,i){return this.id=t||null,this.callback=i,this.getId=function(){return this.id},this.setId=function(t){return this.id=t,this},this.hasId=function(){return null!==this.id},this.update=function(t){return this.callback(t,this.id),this},n(this,{})}function o(){return this.callbackCollection=new s,this.attachCallback=function(t){return this.callbackCollection.add(t),this},this.detachCallback=function(t){return this.callbackCollection.remove(t),this},this.notify=function(){const t=this;return this.callbackCollection.each((function(i,n){i.update(t)})),this},n(this,{})}var l=Object.freeze({__proto__:null,Callback:h,Subject:o});function u(t,i,e){return n(this,function(t,i,n){return function(t,i){if(t.tagName.toUpperCase()===i.toUpperCase())return!0;throw"ERR_ELEMENT_NAME"}(n=n||t.createElement(i),i),n}(t,i,e))}var c=Object.freeze({__proto__:null,Element:u});var a=Object.freeze({__proto__:null,Component:function(t,i,e,s){const r=new u(i,e,s);return this.presenter=t,this.initialize=function(){return this.presenter.initialize(this),this},this.destroy=function(){return this.presenter.destroy(),this},n(this,r)},ComponentPresenter:function(t){this.state=t,this.update=function(t,i){throw"ERR_COMPONENT_UPDATE"};let i=null;return this.component=null,this.initialize=function(t){return this.component=t,i=new h("ComponentPresenter",this.update),this.state.attachCallback(i),this.state.notify(),this},this.destroy=function(){return this.component=null,this.state.detachCallback(i),i=null,this},n(this,{})},ComponentState:function(){return n(this,new o)}});const f={version:"1.0.0"};return t.Base=e,t.Collection=r,t.Component=a,t.Element=c,t.Observe=l,t.metadata=f,Object.defineProperty(t,"__esModule",{value:!0}),t}({});
//# sourceMappingURL=elementary.min.js.map