-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmozart.min.js
1 lines (1 loc) · 1.07 KB
/
mozart.min.js
1
class Component{constructor(e){let t={name:void 0,store:{},assign(e){let r={};for(let o in t){let i=t[o];r[o]={value:i,writable:!0}}for(let l in Object.defineProperties(e,r),e){let a=Object.getOwnPropertyDescriptor(e,l);a.get?Object.defineProperty(n,l,{get:()=>e[l]}):a.set?Object.defineProperty(n,l,{set:(...t)=>e[l]=t[0]}):a.value&&"function"==typeof a.value?n[l]=(...t)=>e[l].apply(e,t):n[l]=e[l]}},q(e){let t=`[data-component~="${this.name}"]`;e&&(t+=` ${e}`);let n=document.querySelectorAll(t);return n.length>1?Array.from(n):n[0]},get me(){return this.q()},register(e){this.name=e}},n=new Proxy(t,{set(e,r,o){if(e.hasOwnProperty(r))return e[r]=o;if("function"==typeof o){let i={};for(let l in t){let a=t[l];i[l]={value:a,writable:!0}}return Object.defineProperty(e,r,{value:Object.defineProperties(o,i).bind(n),writable:!0}),!0}throw console.error(`Value ${o} was not a function on ${n.name} component. Type of ${o} is ${typeof o}`),`${n.name}: Value was not a function. Use .store on the component to store new information`},get:(e,t)=>e[t]});return n.register(e),n}}export default Component;