react-ioc
Version:
Hierarchical Dependency Injection for React
3 lines (2 loc) • 18.5 kB
JavaScript
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r(t.ReactIoC={},t.React)}(this,function(t,r){"use strict";var n,e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function i(t,r){return t(r={exports:{}},r.exports),r.exports}!function(t){!function(r){var n="object"==typeof e?e:"object"==typeof self?self:"object"==typeof this?this:Function("return this;")(),o=i(t);function i(t,r){return function(n,e){"function"!=typeof t[n]&&Object.defineProperty(t,n,{configurable:!0,writable:!0,value:e}),r&&r(n,e)}}void 0===n.Reflect?n.Reflect=t:o=i(n.Reflect,o),function(t){var r=Object.prototype.hasOwnProperty,n="function"==typeof Symbol,e=n&&void 0!==Symbol.toPrimitive?Symbol.toPrimitive:"@@toPrimitive",o=n&&void 0!==Symbol.iterator?Symbol.iterator:"@@iterator",i="function"==typeof Object.create,u={__proto__:[]}instanceof Array,f=!i&&!u,c={create:i?function(){return W(Object.create(null))}:u?function(){return W({__proto__:null})}:function(){return W({})},has:f?function(t,n){return r.call(t,n)}:function(t,r){return r in t},get:f?function(t,n){return r.call(t,n)?t[n]:void 0}:function(t,r){return t[r]}},a=Object.getPrototypeOf(Function),s="object"==typeof process&&process.env&&"true"===process.env.REFLECT_METADATA_USE_MAP_POLYFILL,l=s||"function"!=typeof Map||"function"!=typeof Map.prototype.entries?function(){var t={},r=[],n=function(){function t(t,r,n){this.t=0,this.r=t,this.n=r,this.e=n}return t.prototype["@@iterator"]=function(){return this},t.prototype[o]=function(){return this},t.prototype.next=function(){var t=this.t;if(t>=0&&t<this.r.length){var n=this.e(this.r[t],this.n[t]);return t+1>=this.r.length?(this.t=-1,this.r=r,this.n=r):this.t++,{value:n,done:!1}}return{value:void 0,done:!0}},t.prototype.throw=function(t){throw this.t>=0&&(this.t=-1,this.r=r,this.n=r),t},t.prototype.return=function(t){return this.t>=0&&(this.t=-1,this.r=r,this.n=r),{value:t,done:!0}},t}();return function(){function r(){this.r=[],this.n=[],this.o=t,this.i=-2}return Object.defineProperty(r.prototype,"size",{get:function(){return this.r.length},enumerable:!0,configurable:!0}),r.prototype.has=function(t){return this.u(t,!1)>=0},r.prototype.get=function(t){var r=this.u(t,!1);return r>=0?this.n[r]:void 0},r.prototype.set=function(t,r){var n=this.u(t,!0);return this.n[n]=r,this},r.prototype.delete=function(r){var n=this.u(r,!1);if(n>=0){for(var e=this.r.length,o=n+1;o<e;o++)this.r[o-1]=this.r[o],this.n[o-1]=this.n[o];return this.r.length--,this.n.length--,r===this.o&&(this.o=t,this.i=-2),!0}return!1},r.prototype.clear=function(){this.r.length=0,this.n.length=0,this.o=t,this.i=-2},r.prototype.keys=function(){return new n(this.r,this.n,e)},r.prototype.values=function(){return new n(this.r,this.n,i)},r.prototype.entries=function(){return new n(this.r,this.n,u)},r.prototype["@@iterator"]=function(){return this.entries()},r.prototype[o]=function(){return this.entries()},r.prototype.u=function(t,r){return this.o!==t&&(this.i=this.r.indexOf(this.o=t)),this.i<0&&r&&(this.i=this.r.length,this.r.push(t),this.n.push(void 0)),this.i},r}();function e(t,r){return t}function i(t,r){return r}function u(t,r){return[t,r]}}():Map,y=s||"function"!=typeof Set||"function"!=typeof Set.prototype.entries?function(){function t(){this.f=new l}return Object.defineProperty(t.prototype,"size",{get:function(){return this.f.size},enumerable:!0,configurable:!0}),t.prototype.has=function(t){return this.f.has(t)},t.prototype.add=function(t){return this.f.set(t,t),this},t.prototype.delete=function(t){return this.f.delete(t)},t.prototype.clear=function(){this.f.clear()},t.prototype.keys=function(){return this.f.keys()},t.prototype.values=function(){return this.f.values()},t.prototype.entries=function(){return this.f.entries()},t.prototype["@@iterator"]=function(){return this.keys()},t.prototype[o]=function(){return this.keys()},t}():Set,h=new(s||"function"!=typeof WeakMap?function(){var t=16,n=c.create(),e=o();return function(){function t(){this.c=o()}return t.prototype.has=function(t){var r=i(t,!1);return void 0!==r&&c.has(r,this.c)},t.prototype.get=function(t){var r=i(t,!1);return void 0!==r?c.get(r,this.c):void 0},t.prototype.set=function(t,r){var n=i(t,!0);return n[this.c]=r,this},t.prototype.delete=function(t){var r=i(t,!1);return void 0!==r&&delete r[this.c]},t.prototype.clear=function(){this.c=o()},t}();function o(){var t;do{t="@@WeakMap@@"+f()}while(c.has(n,t));return n[t]=!0,t}function i(t,n){if(!r.call(t,e)){if(!n)return;Object.defineProperty(t,e,{value:c.create()})}return t[e]}function u(t,r){for(var n=0;n<r;++n)t[n]=255*Math.random()|0;return t}function f(){var r=function(t){if("function"==typeof Uint8Array)return"undefined"!=typeof crypto?crypto.getRandomValues(new Uint8Array(t)):"undefined"!=typeof msCrypto?msCrypto.getRandomValues(new Uint8Array(t)):u(new Uint8Array(t),t);return u(new Array(t),t)}(t);r[6]=79&r[6]|64,r[8]=191&r[8]|128;for(var n="",e=0;e<t;++e){var o=r[e];4!==e&&6!==e&&8!==e||(n+="-"),o<16&&(n+="0"),n+=o.toString(16).toLowerCase()}return n}}():WeakMap);function v(t,r,n){var e=h.get(t);if(j(e)){if(!n)return;e=new l,h.set(t,e)}var o=e.get(r);if(j(o)){if(!n)return;o=new l,e.set(r,o)}return o}function p(t,r,n){var e=v(r,n,!1);return!j(e)&&!!e.has(t)}function b(t,r,n){var e=v(r,n,!1);if(!j(e))return e.get(t)}function d(t,r,n,e){var o=v(n,e,!0);o.set(t,r)}function w(t,r){var n=[],e=v(t,r,!1);if(j(e))return n;for(var i=e.keys(),u=function(t){var r=A(t,o);if(!E(r))throw new TypeError;var n=r.call(t);if(!g(n))throw new TypeError;return n}(i),f=0;;){var c=x(u);if(!c)return n.length=f,n;var a=c.value;try{n[f]=a}catch(t){try{P(u)}finally{throw t}}f++}}function m(t){if(null===t)return 1;switch(typeof t){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return null===t?1:6;default:return 6}}function j(t){return void 0===t}function S(t){return null===t}function g(t){return"object"==typeof t?null!==t:"function"==typeof t}function _(t,r){switch(m(t)){case 0:case 1:case 2:case 3:case 4:case 5:return t}var n=3===r?"string":5===r?"number":"default",o=A(t,e);if(void 0!==o){var i=o.call(t,n);if(g(i))throw new TypeError;return i}return function(t,r){if("string"===r){var n=t.toString;if(E(n)){var e=n.call(t);if(!g(e))return e}var o=t.valueOf;if(E(o)){var e=o.call(t);if(!g(e))return e}}else{var o=t.valueOf;if(E(o)){var e=o.call(t);if(!g(e))return e}var i=t.toString;if(E(i)){var e=i.call(t);if(!g(e))return e}}throw new TypeError}(t,"default"===n?"number":n)}function O(t){var r=_(t,3);return"symbol"==typeof r?r:function(t){return""+t}(r)}function T(t){return Array.isArray?Array.isArray(t):t instanceof Object?t instanceof Array:"[object Array]"===Object.prototype.toString.call(t)}function E(t){return"function"==typeof t}function M(t){return"function"==typeof t}function A(t,r){var n=t[r];if(null!=n){if(!E(n))throw new TypeError;return n}}function x(t){var r=t.next();return!r.done&&r}function P(t){var r=t.return;r&&r.call(t)}function U(t){var r=Object.getPrototypeOf(t);if("function"!=typeof t||t===a)return r;if(r!==a)return r;var n=t.prototype,e=n&&Object.getPrototypeOf(n);if(null==e||e===Object.prototype)return r;var o=e.constructor;return"function"!=typeof o?r:o===t?r:o}function W(t){return t.__=void 0,delete t.__,t}t("decorate",function(t,r,n,e){if(j(n)){if(!T(t))throw new TypeError;if(!M(r))throw new TypeError;return function(t,r){for(var n=t.length-1;n>=0;--n){var e=t[n],o=e(r);if(!j(o)&&!S(o)){if(!M(o))throw new TypeError;r=o}}return r}(t,r)}if(!T(t))throw new TypeError;if(!g(r))throw new TypeError;if(!g(e)&&!j(e)&&!S(e))throw new TypeError;return S(e)&&(e=void 0),n=O(n),function(t,r,n,e){for(var o=t.length-1;o>=0;--o){var i=t[o],u=i(r,n,e);if(!j(u)&&!S(u)){if(!g(u))throw new TypeError;e=u}}return e}(t,r,n,e)}),t("metadata",function(t,r){return function(n,e){if(!g(n))throw new TypeError;if(!j(e)&&!function(t){switch(m(t)){case 3:case 4:return!0;default:return!1}}(e))throw new TypeError;d(t,r,n,e)}}),t("defineMetadata",function(t,r,n,e){if(!g(n))throw new TypeError;j(e)||(e=O(e));return d(t,r,n,e)}),t("hasMetadata",function(t,r,n){if(!g(r))throw new TypeError;j(n)||(n=O(n));return function t(r,n,e){var o=p(r,n,e);if(o)return!0;var i=U(n);if(!S(i))return t(r,i,e);return!1}(t,r,n)}),t("hasOwnMetadata",function(t,r,n){if(!g(r))throw new TypeError;j(n)||(n=O(n));return p(t,r,n)}),t("getMetadata",function(t,r,n){if(!g(r))throw new TypeError;j(n)||(n=O(n));return function t(r,n,e){var o=p(r,n,e);if(o)return b(r,n,e);var i=U(n);if(!S(i))return t(r,i,e);return}(t,r,n)}),t("getOwnMetadata",function(t,r,n){if(!g(r))throw new TypeError;j(n)||(n=O(n));return b(t,r,n)}),t("getMetadataKeys",function(t,r){if(!g(t))throw new TypeError;j(r)||(r=O(r));return function t(r,n){var e=w(r,n);var o=U(r);if(null===o)return e;var i=t(o,n);if(i.length<=0)return e;if(e.length<=0)return i;var u=new y;var f=[];for(var c=0,a=e;c<a.length;c++){var s=a[c],l=u.has(s);l||(u.add(s),f.push(s))}for(var h=0,v=i;h<v.length;h++){var s=v[h],l=u.has(s);l||(u.add(s),f.push(s))}return f}(t,r)}),t("getOwnMetadataKeys",function(t,r){if(!g(t))throw new TypeError;j(r)||(r=O(r));return w(t,r)}),t("deleteMetadata",function(t,r,n){if(!g(r))throw new TypeError;j(n)||(n=O(n));var e=v(r,n,!1);if(j(e))return!1;if(!e.delete(t))return!1;if(e.size>0)return!0;var o=h.get(r);return o.delete(n),o.size>0||(h.delete(r),!0)})}(o)}()}(n||(n={}));var u=function(t,r){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var n in r)r.hasOwnProperty(n)&&(t[n]=r[n])})(t,r)};function f(t,r){function n(){this.constructor=t}u(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}function c(t){return"function"==typeof t}var a=r.createContext(null),s=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return f(r,t),r}(r.Component);var l=null,y="function"==typeof Symbol?Symbol():"__injector__";function h(t,r){for(v.length>0&&(v.forEach(function(t){t()}),v.length=0);t;){var n=t.a.get(r);if(void 0!==n)return n;var e=t.s.get(r);if(e){var o=l;l=t;try{n=e(t)}finally{l=o}return t.a.set(r,n),n}t=t.l}}var v=[];function p(t,r){return c(r)?b(t,r):r?e(t,r):(n=t,e);var n;function e(t,r){t.constructor.contextType=a,n||(n=Reflect.getMetadata("design:type",t,r));var e={configurable:!0,enumerable:!0,get:function(){var t=b(this,n);return Object.defineProperty(this,r,{enumerable:!0,writable:!0,value:t}),t},set:function(t){Object.defineProperty(this,r,{enumerable:!0,writable:!0,value:t})}};return Object.defineProperty(t,r,e),e}}function b(t,r){return h(function(t){var r=t[y];return r||((r=l||t.context)instanceof s?(t[y]=r,r):null)}(t),r)}var d=i(function(t,r){Object.defineProperty(r,"__esModule",{value:!0});var n="function"==typeof Symbol&&Symbol.for,e=n?Symbol.for("react.element"):60103,o=n?Symbol.for("react.portal"):60106,i=n?Symbol.for("react.fragment"):60107,u=n?Symbol.for("react.strict_mode"):60108,f=n?Symbol.for("react.profiler"):60114,c=n?Symbol.for("react.provider"):60109,a=n?Symbol.for("react.context"):60110,s=n?Symbol.for("react.async_mode"):60111,l=n?Symbol.for("react.concurrent_mode"):60111,y=n?Symbol.for("react.forward_ref"):60112,h=n?Symbol.for("react.suspense"):60113,v=n?Symbol.for("react.memo"):60115,p=n?Symbol.for("react.lazy"):60116;function b(t){if("object"==typeof t&&null!==t){var r=t.$$typeof;switch(r){case e:switch(t=t.type){case s:case l:case i:case f:case u:return t;default:switch(t=t&&t.$$typeof){case a:case y:case c:return t;default:return r}}case o:return r}}}function d(t){return b(t)===l}r.typeOf=b,r.AsyncMode=s,r.ConcurrentMode=l,r.ContextConsumer=a,r.ContextProvider=c,r.Element=e,r.ForwardRef=y,r.Fragment=i,r.Profiler=f,r.Portal=o,r.StrictMode=u,r.isValidElementType=function(t){return"string"==typeof t||"function"==typeof t||t===i||t===l||t===f||t===u||t===h||"object"==typeof t&&null!==t&&(t.$$typeof===p||t.$$typeof===v||t.$$typeof===c||t.$$typeof===a||t.$$typeof===y)},r.isAsyncMode=function(t){return d(t)||b(t)===s},r.isConcurrentMode=d,r.isContextConsumer=function(t){return b(t)===a},r.isContextProvider=function(t){return b(t)===c},r.isElement=function(t){return"object"==typeof t&&null!==t&&t.$$typeof===e},r.isForwardRef=function(t){return b(t)===y},r.isFragment=function(t){return b(t)===i},r.isProfiler=function(t){return b(t)===f},r.isPortal=function(t){return b(t)===o},r.isStrictMode=function(t){return b(t)===u}});o(d);d.typeOf,d.AsyncMode,d.ConcurrentMode,d.ContextConsumer,d.ContextProvider,d.Element,d.ForwardRef,d.Fragment,d.Profiler,d.Portal,d.StrictMode,d.isValidElementType,d.isAsyncMode,d.isConcurrentMode,d.isContextConsumer,d.isContextProvider,d.isElement,d.isForwardRef,d.isFragment,d.isProfiler,d.isPortal,d.isStrictMode;var w=i(function(t,r){"production"!==process.env.NODE_ENV&&function(){Object.defineProperty(r,"__esModule",{value:!0});var t="function"==typeof Symbol&&Symbol.for,n=t?Symbol.for("react.element"):60103,e=t?Symbol.for("react.portal"):60106,o=t?Symbol.for("react.fragment"):60107,i=t?Symbol.for("react.strict_mode"):60108,u=t?Symbol.for("react.profiler"):60114,f=t?Symbol.for("react.provider"):60109,c=t?Symbol.for("react.context"):60110,a=t?Symbol.for("react.async_mode"):60111,s=t?Symbol.for("react.concurrent_mode"):60111,l=t?Symbol.for("react.forward_ref"):60112,y=t?Symbol.for("react.suspense"):60113,h=t?Symbol.for("react.memo"):60115,v=t?Symbol.for("react.lazy"):60116;var p=function(t,r){if(void 0===r)throw new Error("`lowPriorityWarning(condition, format, ...args)` requires a warning message argument");if(!t){for(var n=arguments.length,e=Array(n>2?n-2:0),o=2;o<n;o++)e[o-2]=arguments[o];(function(t){for(var r=arguments.length,n=Array(r>1?r-1:0),e=1;e<r;e++)n[e-1]=arguments[e];var o=0,i="Warning: "+t.replace(/%s/g,function(){return n[o++]});"undefined"!=typeof console&&console.warn(i);try{throw new Error(i)}catch(t){}}).apply(void 0,[r].concat(e))}};function b(t){if("object"==typeof t&&null!==t){var r=t.$$typeof;switch(r){case n:var y=t.type;switch(y){case a:case s:case o:case u:case i:return y;default:var h=y&&y.$$typeof;switch(h){case c:case l:case f:return h;default:return r}}case e:return r}}}var d=a,w=s,m=c,j=f,S=n,g=l,_=o,O=u,T=e,E=i,M=!1;function A(t){return b(t)===s}r.typeOf=b,r.AsyncMode=d,r.ConcurrentMode=w,r.ContextConsumer=m,r.ContextProvider=j,r.Element=S,r.ForwardRef=g,r.Fragment=_,r.Profiler=O,r.Portal=T,r.StrictMode=E,r.isValidElementType=function(t){return"string"==typeof t||"function"==typeof t||t===o||t===s||t===u||t===i||t===y||"object"==typeof t&&null!==t&&(t.$$typeof===v||t.$$typeof===h||t.$$typeof===f||t.$$typeof===c||t.$$typeof===l)},r.isAsyncMode=function(t){return M||(M=!0,p(!1,"The ReactIs.isAsyncMode() alias has been deprecated, and will be removed in React 17+. Update your code to use ReactIs.isConcurrentMode() instead. It has the exact same API.")),A(t)||b(t)===a},r.isConcurrentMode=A,r.isContextConsumer=function(t){return b(t)===c},r.isContextProvider=function(t){return b(t)===f},r.isElement=function(t){return"object"==typeof t&&null!==t&&t.$$typeof===n},r.isForwardRef=function(t){return b(t)===l},r.isFragment=function(t){return b(t)===o},r.isProfiler=function(t){return b(t)===u},r.isPortal=function(t){return b(t)===e},r.isStrictMode=function(t){return b(t)===i}}()});o(w);w.typeOf,w.AsyncMode,w.ConcurrentMode,w.ContextConsumer,w.ContextProvider,w.Element,w.ForwardRef,w.Fragment,w.Profiler,w.Portal,w.StrictMode,w.isValidElementType,w.isAsyncMode,w.isConcurrentMode,w.isContextConsumer,w.isContextProvider,w.isElement,w.isForwardRef,w.isFragment,w.isProfiler,w.isPortal,w.isStrictMode;var m=i(function(t){"production"===process.env.NODE_ENV?t.exports=d:t.exports=w}),j={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},S={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},g={};g[m.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0};var _=Object.defineProperty,O=Object.getOwnPropertyNames,T=Object.getOwnPropertySymbols,E=Object.getOwnPropertyDescriptor,M=Object.getPrototypeOf,A=Object.prototype;var x=function t(r,n,e){if("string"!=typeof n){if(A){var o=M(n);o&&o!==A&&t(r,o,e)}var i=O(n);T&&(i=i.concat(T(n)));for(var u=g[r.$$typeof]||j,f=g[n.$$typeof]||j,c=0;c<i.length;++c){var a=i[c];if(!(S[a]||e&&e[a]||f&&f[a]||u&&u[a])){var s=E(n,a);try{_(r,a,s)}catch(t){}}}return r}return r};function P(t){return W(function(r){var n=new t;return n[y]||(n[y]=r),n})}var U="function"==typeof Symbol?Symbol():"__binding__";function W(t){return t[U]=!0,t}function z(t,r){r.forEach(function(r){var n,e,o;Array.isArray(r)?(e=r[0],o=void 0===(n=r[1])?e:n):e=o=r,t.set(e,o[U]?o:P(o))})}var C=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return function(n){var e=new Map;z(e,t);var o=function(t){function o(){var r=null!==t&&t.apply(this,arguments)||this;return r.l=r.context,r.s=e,r.a=new Map,r}return f(o,t),o.prototype.componentWillUnmount=function(){this.a.forEach(function(t){var r;(r=t)&&"object"==typeof r&&c(t.dispose)&&t.dispose()})},o.prototype.render=function(){return r.createElement(a.Provider,{value:this},r.createElement(n,this.props))},o.register=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];z(e,t)},o.WrappedComponent=n,o}(s);return o.contextType=a,x(o,n)}},F=function(t,r){return function(n){return v.push(function(){t().register(r?[n,r]:n)}),n}};t.inject=p,t.provider=C,t.registerIn=F,t.Inject=p,t.Provider=C,t.RegisterIn=F,t.InjectorContext=a,t.toClass=P,t.toFactory=function(t,r){return W(r?function(n){return r.apply(void 0,t.map(function(t){return h(n,t)}))}:t)},t.toExisting=function(t){return W(function(r){return h(r,t)})},t.toValue=function(t){return W(function(){return t})},t.useInstance=function(t){var n=r.useRef(null),e=r.useContext(a);return n.current||(n.current=h(e,t))},t.useInstances=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=r.useRef(null),o=r.useContext(a);return e.current||(e.current=t.map(function(t){return h(o,t)}))},Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=index.umd.min.js.map