UNPKG

mix-classes

Version:

Seamlessly combine class inheritance with composition, guaranteed to work with any class

3 lines (2 loc) 2.51 kB
"use strict";function t(r,e){return(t=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(r,e)}function r(e,n,o){return(r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct:function(r,e,n){var o=[null];o.push.apply(o,e);var u=new(Function.bind.apply(r,o));return n&&t(u,n.prototype),u}).apply(null,arguments)}var e=function(t,r){if(t&&t[n])return t[n].get(r)},n=Symbol("instanceThis"),o=Symbol("mixinClasses"),u=function(t){return"prototype"in t?t:t.Class};exports.Generic=function(t){return{Class:t}},exports.Mix=function(){for(var t=arguments.length,c=new Array(t),i=0;i<t;i++)c[i]=arguments[i];return function(t){var c,i,f=t.map(u),a=(i=function(){for(var t=this,e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];this[c]=new WeakMap,f.forEach(function(e,u){var c,i,f=r(e,o[u]||[]),a=(c=t,i=f,new Proxy(c,{get:function(t,r){return(r in i?i:c)[r]},set:function(t,r,e){return(r in i?i:c)[r]=e,!0}}));t[n].set(e,a),Object.keys(f).forEach(function(r){Object.defineProperty(t,r,{configurable:!0,enumerable:!0,get:function(){return f[r]},set:function(t){return f[r]=t}})})})},c=n,i[o]=f,i);return f.forEach(function(t){var r=function(r){return function(){for(var n=arguments.length,o=new Array(n),u=0;u<n;u++)o[u]=arguments[u];return r.apply(e(this,t),o)}};!function e(n){var u=n.constructor[Symbol.hasInstance];Object.defineProperty(n.constructor,Symbol.hasInstance,{configurable:!0,value:function(r){if(n.isPrototypeOf(r))return!0;if(r&&r.constructor){if(this&&this!==n.constructor)return n.constructor.isPrototypeOf(r.constructor);if(function r(e){var n=e[o];if(!n)return!1;var u=n,c=Array.isArray(u),i=0;for(u=c?u:u[Symbol.iterator]();;){var f;if(c){if(i>=u.length)break;f=u[i++]}else{if((i=u.next()).done)break;f=i.value}if(f===t)return!0;if(r(f))return!0}return!1}(r.constructor))return!0;if(!this)return!1}return u(r)}}),Object.getOwnPropertyNames(n).forEach(function(t){if("constructor"!==t){var e=Object.getOwnPropertyDescriptor(n,t);e.get&&(e.get=r(e.get)),e.set&&(e.set=r(e.set)),"function"==typeof e.value&&(e.value=r(e.value)),a.prototype.hasOwnProperty(t)||Object.defineProperty(a.prototype,t,e)}});var c=Object.getPrototypeOf(n);c&&c!==Object.prototype&&e(c)}(t.prototype)}),a}(c)},exports.getMixin=e; //# sourceMappingURL=mix-classes.cjs.production.js.map