preact-router-lazy
Version:
Async route component for preact-router
2 lines • 2.02 kB
JavaScript
!function(t,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o(require("preact")):"function"==typeof define&&define.amd?define(["preact"],o):t["preact-router-lazy"]=o(t.preact)}(this,function(t){"use strict";function o(t,o){if(!(t instanceof o))throw new TypeError("Cannot call a class as a function")}function n(t,o){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!o||"object"!=typeof o&&"function"!=typeof o?t:o}function e(t,o){if("function"!=typeof o&&null!==o)throw new TypeError("Super expression must either be null or a function, not "+typeof o);t.prototype=Object.create(o&&o.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),o&&(Object.setPrototypeOf?Object.setPrototypeOf(t,o):t.__proto__=o)}var r=Object.assign||function(t){for(var o=1;o<arguments.length;o++){var n=arguments[o];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t};return function(p){function i(){o(this,i);var t=n(this,p.call(this));return t.state={componentData:null},t}return e(i,p),i.prototype.loadComponent=function(){var t=this;if(this.props.component)return this.setState({componentData:this.props.component});var o=this.props.getComponent(this.props.url,function(o){var n=o.component;n&&t.setState({componentData:n})},r({},this.props,this.props.matches));o&&o.then&&function(n){o.then(function(o){if(n!==t.props.url)return void t.setState({componentData:null},function(){t.loadComponent()});t.setState({componentData:o})})}(this.props.url)},i.prototype.componentWillReceiveProps=function(t){var o=this;this.props.path&&this.props.path!==t.path&&this.setState({componentData:null},function(){o.loadComponent()})},i.prototype.componentWillMount=function(){this.loadComponent()},i.prototype.render=function(){if(this.state.componentData)return t.h(this.state.componentData,this.props);if(this.props.loading){return this.props.loading()}return null},i}(t.Component)});
//# sourceMappingURL=index.min.js.map