reactant-router
Version:
A router plugin for Reactant
2 lines (1 loc) • 5.35 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("reactant-module"),require("connected-react-router"),require("history")):"function"==typeof define&&define.amd?define(["exports","react","reactant-module","connected-react-router","history"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).reactantRouter={},t.React,t.reactantModule,t.connectedReactRouter,t.history)}(this,(function(t,e,r,o,n){"use strict";var i=function(t,e){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},i(t,e)};function a(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}"function"==typeof SuppressedError&&SuppressedError;var u=Symbol("RouterOptions"),c=function(t){function n(r){var n,i,a=t.call(this)||this;a.options=r,a.onLocationChanged=o.onLocationChanged,a.routerActions=o.routerActions,a.stateKey="router",a.ConnectedRouter=function(t){return e.createElement(o.ConnectedRouter,{history:a.history},t.children)},a.provider=function(t){return a.autoProvide?e.createElement(a.ConnectedRouter,null,t.children):t.children};var u=(a.options||{}).autoProvide,c=void 0===u||u;return a.autoProvide=c,a.autoCreateHistory=null===(i=null===(n=a.options)||void 0===n?void 0:n.autoCreateHistory)||void 0===i||i,a.autoCreateHistory&&(a.history=a.options.createHistory(),a.middleware=function(t){return function(t){return function(e){if(e.type!==o.CALL_HISTORY_METHOD)return t(e);var r=e.payload,n=r.method,i=r.args,u=void 0===i?[]:i,c=a.history;c[n].apply(c,function(t,e,r){if(r||2===arguments.length)for(var o,n=0,i=e.length;n<i;n++)!o&&n in e||(o||(o=Array.prototype.slice.call(e,0,n)),o[n]=e[n]);return t.concat(o||Array.prototype.slice.call(e))}([],function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var o,n,i=r.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(t){n={error:t}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return a}(u),!1))}}}),a}var c,s;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}(n,t),Object.defineProperty(n.prototype,"store",{get:function(){return this[r.storeKey]},enumerable:!1,configurable:!0}),n.prototype.beforeCombineRootReducers=function(t){var e,n,i,a,u,c;if(Object.prototype.hasOwnProperty.call(t,this.stateKey))throw new Error("The identifier '".concat(this.stateKey,"' has a duplicate name, please reset the option 'stateKey' of 'ReactantRouter' module."));if(this[r.enableAutoComputedKey]){var s=null!==(a=this[r.signalMapKey])&&void 0!==a?a:{};s[this.stateKey]=r.signal({});var l=s[this.stateKey];this[r.signalMapKey]||Object.defineProperties(this,((e={})[r.signalMapKey]={enumerable:!1,configurable:!1,writable:!1,value:s},e));var p=o.connectRouter(null!==(u=this.history)&&void 0!==u?u:this.defaultHistory);return Object.assign(t,((n={})[this.stateKey]=function(t,e){var r=p(t,e);return r!==t&&(l.value=r),r},n))}return Object.assign(t,((i={})[this.stateKey]=o.connectRouter(null!==(c=this.history)&&void 0!==c?c:this.defaultHistory),i))},Object.defineProperty(n.prototype,"router",{get:function(){var t,e;if(this[r.enableAutoComputedKey]){var o=null===(t=this[r.signalMapKey])||void 0===t?void 0:t[this.stateKey];if(o)return o.value}return null===(e=this.store)||void 0===e?void 0:e.getState()[this.stateKey]},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"currentPath",{get:function(){var t;return null===(t=this.router)||void 0===t?void 0:t.location.pathname},enumerable:!1,configurable:!0}),n.prototype.push=function(t,e){var r;null===(r=this.store)||void 0===r||r.dispatch(this.routerActions.push(t,e))},n.prototype.replace=function(t,e){var r;null===(r=this.store)||void 0===r||r.dispatch(this.routerActions.replace(t,e))},n.prototype.go=function(t){var e;null===(e=this.store)||void 0===e||e.dispatch(this.routerActions.go(t))},n.prototype.goBack=function(){var t;null===(t=this.store)||void 0===t||t.dispatch(this.routerActions.goBack())},n.prototype.goForward=function(){var t;null===(t=this.store)||void 0===t||t.dispatch(this.routerActions.goForward())},n=function(t,e,r,o){var n,i=arguments.length,a=i<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,r,o);else for(var u=t.length-1;u>=0;u--)(n=t[u])&&(a=(i<3?n(a):i>3?n(e,r,a):n(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a}([r.injectable({name:"Router"}),(c=0,s=r.inject(u),function(t,e){s(t,e,c)}),a("design:paramtypes",[Object])],n),n}(r.PluginModule);Object.defineProperty(t,"LOCATION_CHANGE",{enumerable:!0,get:function(){return o.LOCATION_CHANGE}}),Object.defineProperty(t,"createBrowserHistory",{enumerable:!0,get:function(){return n.createBrowserHistory}}),Object.defineProperty(t,"createHashHistory",{enumerable:!0,get:function(){return n.createHashHistory}}),Object.defineProperty(t,"createMemoryHistory",{enumerable:!0,get:function(){return n.createMemoryHistory}}),t.Router=c,t.RouterOptions=u}));