mics
Version:
Multiple Inheritance Class System: Intuitive mixins for ES6 classes
2 lines • 4.15 kB
JavaScript
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var r in n)("object"==typeof exports?exports:t)[r]=n[r]}}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){"use strict";function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function u(){function t(e){var n=c(e,t)?e:i(e);return-1===t.classes.indexOf(n)&&t.classes.push(n),n}for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];var o=!y(n[0])&&n.shift()||d,i=y(n[n.length-1])&&n.pop()||m;o=a(o)?o.class:m(o),n.length&&(i=function(t){return function(e){return t(n.reduce(function(t,e){return e.mixin(t)},e))}}(i)),Object.defineProperties(t,{classes:{value:[],writable:!1},mixins:{value:n,writable:!1}});var u=t(o),f=u.hasOwnProperty("constructor")?u.constructor.bind(u):function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return new(Function.prototype.bind.apply(u,[null].concat(e)))};return Object.getOwnPropertyNames(u).forEach(function(t){return Object.defineProperty(f,t,{value:u[t]})}),Object.defineProperties(f,{mixin:{value:t,writable:!1},class:{value:u,writable:!1},interface:{get:function(t){return function(){return t||(t=s(u.prototype))}}()}})}function c(t,e){if("object"==(void 0===t?"undefined":b(t))){if(t instanceof e)return!0;if(e.class&&t instanceof e.class)return!0;if(e.mixin&&e.mixin.classes)return e.mixin.classes.reduce(function(e,n){return e||c(t,n)},!1)}else if("function"==typeof t){if(t.mixin&&-1!==t.mixin.mixins.indexOf(e))return!0;for(var n=t;n!==Object;){if(n===e||n===e.class)return!0;if(e.mixin&&e.mixin.classes&&-1!==e.mixin.classes.indexOf(n))return!0;n=Object.getPrototypeOf(n.prototype).constructor}}return!1}function f(t,e){if(c(t,e))return!0;var n=e.interface||"function"==typeof e&&s(e.prototype),r="function"==typeof t?t.interface||s(t.prototype):t;return n&&Object.keys(n).reduce(function(t,e){return t&&("function"==typeof n[e]?"function"==typeof r[e]:e in r)},!0)}function s(t){return p(t).reduce(function(e,n){return e[n]=t[n],e},{})}function p(t){for(var e=[];t!==Object.prototype;)Object.getOwnPropertyNames(t).reduce(function(t,e){return-1===t.indexOf(e)?t.push(e)&&t:t},e),t=Object.getPrototypeOf(t).constructor.prototype;return e}function a(t){return"function"==typeof t&&!!t.mixin}function l(t){if("function"!=typeof t)return!1;var e=t.toString();return/^class\s/.test(e)||/^.*classCallCheck\(/.test(e.replace(/^[^{]*{\s*/,"").replace(/\s*}[^}]*$/,""))}function y(t){return"function"==typeof t&&!a(t)&&!l(t)&&1==t.length}Object.defineProperty(e,"__esModule",{value:!0}),n.d(e,"mix",function(){return u}),n.d(e,"is",function(){return c}),n.d(e,"like",function(){return f});var b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},d=function t(){i(this,t)},m=function(t){return{}[t.name||"Object"]=function(t){function e(){return i(this,e),r(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return o(e,t),e}(t)}}])});
//# sourceMappingURL=mics.min.js.map