UNPKG

mix-classes

Version:

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

3 lines (2 loc) 2.68 kB
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t=t||self)["mix-classes"]={})}(this,function(t){"use strict";function r(t,e){return(r=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t})(t,e)}function e(t,n,o){return(e=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(t,e,n){var o=[null];o.push.apply(o,e);var u=new(Function.bind.apply(t,o));return n&&r(u,n.prototype),u}).apply(null,arguments)}var n=function(t,r){if(t&&t[o])return t[o].get(r)},o=Symbol("instanceThis"),u=Symbol("mixinClasses"),c=function(t){return"prototype"in t?t:t.Class};t.Generic=function(t){return{Class:t}},t.Mix=function(){for(var t=arguments.length,r=new Array(t),i=0;i<t;i++)r[i]=arguments[i];return function(t){var r,i,f=t.map(c),a=(i=function(){for(var t=this,n=arguments.length,u=new Array(n),c=0;c<n;c++)u[c]=arguments[c];this[r]=new WeakMap,f.forEach(function(r,n){var c,i,f=e(r,u[n]||[]),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[o].set(r,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}})})})},r=o,i[u]=f,i);return f.forEach(function(t){var r=function(r){return function(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];return r.apply(n(this,t),o)}};!function e(n){var o=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[u];if(!n)return!1;var o=n,c=Array.isArray(o),i=0;for(o=c?o:o[Symbol.iterator]();;){var f;if(c){if(i>=o.length)break;f=o[i++]}else{if((i=o.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 o(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}(r)},t.getMixin=n}); //# sourceMappingURL=mix-classes.umd.production.js.map