with-lifecycles
Version:
An easy way to turn stateless functional components into class components with state and lifecycles.
2 lines • 4.11 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):"object"==typeof exports?exports.withLifecycles=e(require("react")):t.withLifecycles=e(t.React)}(window,function(t){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:o})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=4)}([function(e,n){e.exports=t},function(t,e,n){(function(e){var n=9007199254740991,o="[object Arguments]",r="[object Function]",c="[object GeneratorFunction]",i="object"==typeof e&&e&&e.Object===Object&&e,u="object"==typeof self&&self&&self.Object===Object&&self,a=i||u||Function("return this")();function f(t,e){for(var n=-1,o=e.length,r=t.length;++n<o;)t[r+n]=e[n];return t}var l=Object.prototype,p=l.hasOwnProperty,s=l.toString,b=a.Symbol,d=l.propertyIsEnumerable,h=b?b.isConcatSpreadable:void 0;function y(t){return m(t)||function(t){return function(t){return function(t){return!!t&&"object"==typeof t}(t)&&function(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=n}(t.length)&&!function(t){var e=function(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}(t)?s.call(t):"";return e==r||e==c}(t)}(t)}(t)&&p.call(t,"callee")&&(!d.call(t,"callee")||s.call(t)==o)}(t)||!!(h&&t&&t[h])}var m=Array.isArray;t.exports=function(t){return t&&t.length?function t(e,n,o,r,c){var i=-1,u=e.length;for(o||(o=y),c||(c=[]);++i<u;){var a=e[i];n>0&&o(a)?n>1?t(a,n-1,o,r,c):f(c,a):r||(c[c.length]=a)}return c}(t,1):[]}}).call(this,n(2))},function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";n.r(e),n.d(e,"default",function(){return f});var o=n(0),r=n.n(o),c=n(1);var i={instance:["componentWillMount","UNSAFE_componentWillMount","componentDidMount","componentWillReceiveProps","UNSAFE_componentWillReceiveProps","shouldComponentUpdate","componentWillUpdate","UNSAFE_componentWillUpdate","getSnapshotBeforeUpdate","componentDidUpdate","componentWillUnmount","componentDidCatch"],static:["getDerivedStateFromProps"],other:["getInitialState","mapStateToProps"]},u=n.n(c)()(Object.values(i));function a(t){return{state:t}}function f(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.mapStateToProps||a,n=Object.keys(t).filter(function(t){return!1===u.includes(t)});return function(o){var c=function(c){function i(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i);var n=function(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}(this,c.call(this,e));return n.state=t.getInitialState?t.getInitialState(e):{},n.boundSetState=n.setState.bind(n),n}return function(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)}(i,c),i.prototype.render=function(){var c=this,i=e(this.state,this.props);return n.forEach(function(e){return i[e]=function(n){return t[e]({event:n,state:c.state,props:c.props,setState:c.boundSetState})}}),r.a.createElement(o,i)},i}(r.a.Component);return i.instance.forEach(function(e){var n=t[e];n&&(c.prototype[e]=n)}),i.static.forEach(function(e){var n=t[e];n&&(c[e]=n)}),c.displayName="withLifecycles("+o.name,c}}},function(t,e,n){t.exports=n(3)}]).default});
//# sourceMappingURL=with-lifecycles.min.js.map