react-router-concent 2.2.5 → 2.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("concent"),require("react"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","concent","react","react-router-dom"],t):t(e["react-router-concent"]={},e.concent,e.React,e.rrd)}(this,(function(e,t,n,o){"use strict";var r="default"in t?t.default:t,c=null,i=Array.prototype.slice,a={callByApi:!1,callTime:0};function l(){throw new Error("you may forget to initialize <ConnectRouter /> or call createHistoryProxy in your app!")}function u(){var e=i.call(arguments),t=e[0],n=i.call(e[1]);c?(a={callByApi:!0,callTime:Date.now()},c[t].apply(null,n)):l()}function s(){return a}function f(e){c=e}var d=null;function y(){if(d)return d;var e={block:function(){u("block",arguments)},createHref:function(){u("createHref",arguments)},go:function(){u("go",arguments)},goBack:function(){u("goBack",arguments)},goForward:function(){u("goForward",arguments)},listen:function(){u("listen",arguments)},push:function(){u("push",arguments)},replace:function(){u("replace",arguments)},getRouterHistory:function(){return c}};return window&&window.location&&(e.location=window.location),d=e,window&&!window.cc_history&&(window.cc_history=d),d}const p="$$CONCENT_ROUTER",g="onUrlChanged";var h=p,m=g;const w=function(e){h=e},_=function(){return h},v=function(e){m=e},C=function(){return m};var R=["PUSH","POP","REPLACE"],P=0;let x,k=1;function E(e,n){e.__insId||(e.__insId=(k++,k),x=e.__insId);var o=!0===n;P>0&&!t.ccContext.isHotReloadMode()?console.warn("historyProxy already been created! you can not init ConnectedRouter or call createHistoryProxy more than one time."):(P+=1,f(e),e.listen(((n,r)=>{if(e.__insId===x){var c=_(),i=C(),l=s();if(Date.now()-l.time>300&&(a={callByApi:!1,callTime:0}),R.includes(r))t.getState(c)?t.setState(c,n):console.warn("forget to call configRouterModule after cc.run, react-router-concent will ignore writing the changed state");setTimeout((function(){if(o)t.emit(i,n,r,e);else{var c=Date.now();t.emit({name:i,canPerform:e=>{var t=e.ctx.initTime;return c-t>400}},n,r,e)}}),300)}})))}var H={id:"__connect_router_span_by_fantasticsoul__",style:{display:"none",width:0,height:0}},N=o.withRouter(class extends n.Component{constructor(e,t){super(e,t);var n=e.history;E(n,!0===e.callUrlChangedOnInit),e.connected&&e.connected(n)}render(){return this.props.children||n.createElement("span",H)}}),I=y();const T=N,U=function(e){var t=e.style,o=e.to,r=e.onClick,c={className:e.className,href:"javascript:;",onClick:function(t){t.stopPropagation&&(!1===e.stop||t.stopPropagation()),I.push(o),r&&r(o)},style:t};return n.createElement("a",c,e.children)},b=y(),A=E,B=(e={})=>{const t=e.module||p,n=e.onUrlChanged||g;w(t),v(n),r.configure(t,{state:{hash:"",key:"",pathname:"",search:"",state:null}})},L=_,M=C,O=s;var j={ConnectRouter:T,Link:U,history:b,createHistoryProxy:A,configureRoute:B,getModuleName:L,getUrlChangedEvName:M,getLatestCallInfo:O};e.ConnectRouter=T,e.Link=U,e.history=b,e.createHistoryProxy=A,e.configureRoute=B,e.getModuleName=L,e.getUrlChangedEvName=M,e.getLatestCallInfo=O,e.default=j,Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("concent"),require("react"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","concent","react","react-router-dom"],t):t(e["react-router-concent"]={},e.concent,e.React,e.rrd)}(this,(function(e,t,n,o){"use strict";var r="default"in t?t.default:t,c=null,i=Array.prototype.slice,a={callByApi:!1,callTime:0};function l(){throw new Error("you may forget to initialize <ConnectRouter /> or call createHistoryProxy in your app!")}function u(){var e=i.call(arguments),t=e[0],n=i.call(e[1]);c?(a={callByApi:!0,callTime:Date.now()},c[t].apply(null,n)):l()}function s(){return a}function f(e){c=e}var d=null;function y(){if(d)return d;var e={block:function(){u("block",arguments)},createHref:function(){u("createHref",arguments)},go:function(){u("go",arguments)},goBack:function(){u("goBack",arguments)},goForward:function(){u("goForward",arguments)},listen:function(){u("listen",arguments)},push:function(){u("push",arguments)},replace:function(){u("replace",arguments)},getRouterHistory:function(){return c}};return window&&window.location&&(e.location=window.location),d=e,window&&!window.cc_history&&(window.cc_history=d),d}const p="$$CONCENT_ROUTER",g="onUrlChanged";var h=p,m=g;const w=function(e){h=e},_=function(){return h},C=function(e){m=e},v=function(){return m};var R=["PUSH","POP","REPLACE"],P=0;let x,k=1;function E(e,n,o){e.__insId||(e.__insId=(k++,k),x=e.__insId);var r=!0===n;P>0&&!t.ccContext.isHotReloadMode()?console.warn("historyProxy already been created! you can not init ConnectedRouter or call createHistoryProxy more than one time."):(P+=1,f(e),e.listen(((n,c)=>{if(e.__insId===x){o&&o(n,c);var i=_(),l=v(),u=s();if(Date.now()-u.time>300&&(a={callByApi:!1,callTime:0}),R.includes(c))t.getState(i)?t.setState(i,n):console.warn("forget to call configRouterModule after cc.run, react-router-concent will ignore writing the changed state");setTimeout((function(){if(r)t.emit(l,n,c,e);else{var o=Date.now();t.emit({name:l,canPerform:e=>{var t=e.ctx.initTime;return o-t>400}},n,c,e)}}),300)}})))}var H={id:"__connect_router_span_by_fantasticsoul__",style:{display:"none",width:0,height:0}},N=o.withRouter(class extends n.Component{constructor(e,t){super(e,t);var n=e.history;E(n,!0===e.callUrlChangedOnInit,e.onUrlChange),e.connected&&e.connected(n)}render(){return this.props.children||n.createElement("span",H)}}),U=y();const I=N,T=function(e){var t=e.style,o=e.to,r=e.onClick,c={className:e.className,href:"javascript:;",onClick:function(t){t.stopPropagation&&(!1===e.stop||t.stopPropagation()),U.push(o),r&&r(o)},style:t};return n.createElement("a",c,e.children)},b=y(),A=E,B=(e={})=>{const t=e.module||p,n=e.onUrlChanged||g;w(t),C(n),r.configure(t,{state:{hash:"",key:"",pathname:"",search:"",state:null}})},L=_,M=v,O=s;var j={ConnectRouter:I,Link:T,history:b,createHistoryProxy:A,configureRoute:B,getModuleName:L,getUrlChangedEvName:M,getLatestCallInfo:O};e.ConnectRouter=I,e.Link=T,e.history=b,e.createHistoryProxy=A,e.configureRoute=B,e.getModuleName=L,e.getUrlChangedEvName=M,e.getLatestCallInfo=O,e.default=j,Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("concent"),require("react"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","concent","react","react-router-dom"],t):t(e["react-router-concent"]={},e.concent,e.React,e.rrd)}(this,(function(e,t,n,o){"use strict";var r="default"in t?t.default:t,c=null,i=Array.prototype.slice,a={callByApi:!1,callTime:0};function l(){throw new Error("you may forget to initialize <ConnectRouter /> or call createHistoryProxy in your app!")}function u(){var e=i.call(arguments),t=e[0],n=i.call(e[1]);c?(a={callByApi:!0,callTime:Date.now()},c[t].apply(null,n)):l()}function s(){return a}function f(e){c=e}var d=null;function y(){if(d)return d;var e={block:function(){u("block",arguments)},createHref:function(){u("createHref",arguments)},go:function(){u("go",arguments)},goBack:function(){u("goBack",arguments)},goForward:function(){u("goForward",arguments)},listen:function(){u("listen",arguments)},push:function(){u("push",arguments)},replace:function(){u("replace",arguments)},getRouterHistory:function(){return c}};return window&&window.location&&(e.location=window.location),d=e,window&&!window.cc_history&&(window.cc_history=d),d}const p="$$CONCENT_ROUTER",g="onUrlChanged";var h=p,m=g;const w=function(e){h=e},_=function(){return h},v=function(e){m=e},C=function(){return m};var R=["PUSH","POP","REPLACE"],P=0;let x,k=1;function E(e,n){e.__insId||(e.__insId=(k++,k),x=e.__insId);var o=!0===n;P>0&&!t.ccContext.isHotReloadMode()?console.warn("historyProxy already been created! you can not init ConnectedRouter or call createHistoryProxy more than one time."):(P+=1,f(e),e.listen(((n,r)=>{if(e.__insId===x){var c=_(),i=C(),l=s();if(Date.now()-l.time>300&&(a={callByApi:!1,callTime:0}),R.includes(r))t.getState(c)?t.setState(c,n):console.warn("forget to call configRouterModule after cc.run, react-router-concent will ignore writing the changed state");setTimeout((function(){if(o)t.emit(i,n,r,e);else{var c=Date.now();t.emit({name:i,canPerform:e=>{var t=e.ctx.initTime;return c-t>400}},n,r,e)}}),300)}})))}var H={id:"__connect_router_span_by_fantasticsoul__",style:{display:"none",width:0,height:0}},N=o.withRouter(class extends n.Component{constructor(e,t){super(e,t);var n=e.history;E(n,!0===e.callUrlChangedOnInit),e.connected&&e.connected(n)}render(){return this.props.children||n.createElement("span",H)}}),I=y();const T=N,U=function(e){var t=e.style,o=e.to,r=e.onClick,c={className:e.className,href:"javascript:;",onClick:function(t){t.stopPropagation&&(!1===e.stop||t.stopPropagation()),I.push(o),r&&r(o)},style:t};return n.createElement("a",c,e.children)},b=y(),A=E,B=(e={})=>{const t=e.module||p,n=e.onUrlChanged||g;w(t),v(n),r.configure(t,{state:{hash:"",key:"",pathname:"",search:"",state:null}})},L=_,M=C,O=s;var j={ConnectRouter:T,Link:U,history:b,createHistoryProxy:A,configureRoute:B,getModuleName:L,getUrlChangedEvName:M,getLatestCallInfo:O};e.ConnectRouter=T,e.Link=U,e.history=b,e.createHistoryProxy=A,e.configureRoute=B,e.getModuleName=L,e.getUrlChangedEvName=M,e.getLatestCallInfo=O,e.default=j,Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("concent"),require("react"),require("react-router-dom")):"function"==typeof define&&define.amd?define(["exports","concent","react","react-router-dom"],t):t(e["react-router-concent"]={},e.concent,e.React,e.rrd)}(this,(function(e,t,n,o){"use strict";var r="default"in t?t.default:t,c=null,i=Array.prototype.slice,a={callByApi:!1,callTime:0};function l(){throw new Error("you may forget to initialize <ConnectRouter /> or call createHistoryProxy in your app!")}function u(){var e=i.call(arguments),t=e[0],n=i.call(e[1]);c?(a={callByApi:!0,callTime:Date.now()},c[t].apply(null,n)):l()}function s(){return a}function f(e){c=e}var d=null;function y(){if(d)return d;var e={block:function(){u("block",arguments)},createHref:function(){u("createHref",arguments)},go:function(){u("go",arguments)},goBack:function(){u("goBack",arguments)},goForward:function(){u("goForward",arguments)},listen:function(){u("listen",arguments)},push:function(){u("push",arguments)},replace:function(){u("replace",arguments)},getRouterHistory:function(){return c}};return window&&window.location&&(e.location=window.location),d=e,window&&!window.cc_history&&(window.cc_history=d),d}const p="$$CONCENT_ROUTER",g="onUrlChanged";var h=p,m=g;const w=function(e){h=e},_=function(){return h},C=function(e){m=e},v=function(){return m};var R=["PUSH","POP","REPLACE"],P=0;let x,k=1;function E(e,n,o){e.__insId||(e.__insId=(k++,k),x=e.__insId);var r=!0===n;P>0&&!t.ccContext.isHotReloadMode()?console.warn("historyProxy already been created! you can not init ConnectedRouter or call createHistoryProxy more than one time."):(P+=1,f(e),e.listen(((n,c)=>{if(e.__insId===x){o&&o(n,c);var i=_(),l=v(),u=s();if(Date.now()-u.time>300&&(a={callByApi:!1,callTime:0}),R.includes(c))t.getState(i)?t.setState(i,n):console.warn("forget to call configRouterModule after cc.run, react-router-concent will ignore writing the changed state");setTimeout((function(){if(r)t.emit(l,n,c,e);else{var o=Date.now();t.emit({name:l,canPerform:e=>{var t=e.ctx.initTime;return o-t>400}},n,c,e)}}),300)}})))}var H={id:"__connect_router_span_by_fantasticsoul__",style:{display:"none",width:0,height:0}},N=o.withRouter(class extends n.Component{constructor(e,t){super(e,t);var n=e.history;E(n,!0===e.callUrlChangedOnInit,e.onUrlChange),e.connected&&e.connected(n)}render(){return this.props.children||n.createElement("span",H)}}),U=y();const I=N,T=function(e){var t=e.style,o=e.to,r=e.onClick,c={className:e.className,href:"javascript:;",onClick:function(t){t.stopPropagation&&(!1===e.stop||t.stopPropagation()),U.push(o),r&&r(o)},style:t};return n.createElement("a",c,e.children)},b=y(),A=E,B=(e={})=>{const t=e.module||p,n=e.onUrlChanged||g;w(t),C(n),r.configure(t,{state:{hash:"",key:"",pathname:"",search:"",state:null}})},L=_,M=v,O=s;var j={ConnectRouter:I,Link:T,history:b,createHistoryProxy:A,configureRoute:B,getModuleName:L,getUrlChangedEvName:M,getLatestCallInfo:O};e.ConnectRouter=I,e.Link=T,e.history=b,e.createHistoryProxy=A,e.configureRoute=B,e.getModuleName=L,e.getUrlChangedEvName=M,e.getLatestCallInfo=O,e.default=j,Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -4,6 +4,20 @@ import createHistoryProxy from '../util/createHistoryProxy';
4
4
 
5
5
  var spanProps = { id: '__connect_router_span_by_fantasticsoul__', style: { display: 'none', width: 0, height: 0 } };
6
6
 
7
+ var withRouter = rrd.withRouter;
8
+ if (!withRouter) {
9
+ // v6 版本不再暴露 withRouter
10
+ withRouter = (Component) => {
11
+ const Wrapper = (props) => {
12
+ const history = rrd.useHistory();
13
+ return React.createElement(Component, { history, ...props });
14
+ };
15
+
16
+ return Wrapper;
17
+ };
18
+ }
19
+
20
+
7
21
  export default rrd.withRouter(
8
22
  class extends React.Component {
9
23
  constructor(props, context) {
@@ -11,7 +25,7 @@ export default rrd.withRouter(
11
25
  var history = props.history;
12
26
  var callUrlChangedOnInit = props.callUrlChangedOnInit === true;
13
27
 
14
- createHistoryProxy(history, callUrlChangedOnInit);
28
+ createHistoryProxy(history, callUrlChangedOnInit, props.onUrlChange);
15
29
  if (props.connected) {
16
30
  props.connected(history);
17
31
  }
package/es/index.d.ts CHANGED
@@ -9,6 +9,10 @@ export const ROUTER_MODULE: '$$CONCENT_ROUTER';
9
9
 
10
10
  type CRProps = {
11
11
  callUrlChangedOnInit?: boolean,
12
+ /**
13
+ * 相比 callUrlChangedOnInit,这个是实时的,没有延迟,方便做一些更方便的清理操作动作
14
+ */
15
+ onUrlChange?: (param: any, action: any) => void;
12
16
  connected?: (History: H.History) => void,
13
17
  };
14
18
  export class ConnectRouter extends Component<CRProps, {}> { }
@@ -35,7 +39,7 @@ export declare const history: {
35
39
  location: Location,
36
40
  };
37
41
 
38
- export function createHistoryProxy(history: H.History, callUrlChangedOnInit?: boolean): void;
42
+ export function createHistoryProxy(history: H.History, callUrlChangedOnInit?: boolean, onUrlChange?: CRProps['onUrlChange']): void;
39
43
  export function configureRoute(config?: { module?: string, onUrlChanged?: string }): void;
40
44
  export interface IRouterState<T extends any = any> {
41
45
  hash: string,
@@ -18,7 +18,7 @@ function getInsId() {
18
18
  return insId;
19
19
  }
20
20
 
21
- export default function createHistoryProxy(history, callUrlChangedOnInit) {
21
+ export default function createHistoryProxy(history, callUrlChangedOnInit, onUrlChange) {
22
22
 
23
23
  if (!history.__insId) {
24
24
  history.__insId = getInsId();
@@ -42,6 +42,7 @@ export default function createHistoryProxy(history, callUrlChangedOnInit) {
42
42
  // 防止CodeSandbox热加载模式下,多个history实例同时监听都有效
43
43
  // 只能让最新的一个history的监听起效
44
44
  if (history.__insId !== validInsId) return;
45
+ if (onUrlChange) onUrlChange(param, action);
45
46
 
46
47
  var modName = confMod.getModuleName();
47
48
  var urlChangedEvName = confMod.getUrlChangedEvName();
@@ -60,17 +61,17 @@ export default function createHistoryProxy(history, callUrlChangedOnInit) {
60
61
  }
61
62
  }
62
63
 
63
- //给300毫秒延迟,
64
- //既让concent有足够时间把该卸载的组件卸掉
65
- //也让concent有足够的时间把改挂的组件全部挂上(对于那种初次挂的组件)
66
- //然后在去刷新对应的cc组件
64
+ // 给300毫秒延迟,
65
+ // 既让concent有足够时间把该卸载的组件卸掉
66
+ // 也让concent有足够的时间把该挂的组件全部挂上(对于那种初次挂的组件)
67
+ // 然后再去刷新对应的cc组件
67
68
  setTimeout(function () {
68
69
  //onUrlChanged在组件初次挂载的时候也会执行
69
70
  if (_callUrlChangedOnInit) {
70
71
  cc.emit(urlChangedEvName, param, action, history);
71
72
  return;
72
73
  }
73
-
74
+
74
75
  var now = Date.now();
75
76
  cc.emit({
76
77
  name: urlChangedEvName, canPerform: ref => {
@@ -9,12 +9,29 @@ var spanProps = {
9
9
  height: 0
10
10
  }
11
11
  };
12
+ var withRouter = rrd.withRouter;
13
+
14
+ if (!withRouter) {
15
+ // v6 版本不再暴露 withRouter
16
+ withRouter = Component => {
17
+ const Wrapper = props => {
18
+ const history = rrd.useHistory();
19
+ return React.createElement(Component, {
20
+ history,
21
+ ...props
22
+ });
23
+ };
24
+
25
+ return Wrapper;
26
+ };
27
+ }
28
+
12
29
  export default rrd.withRouter(class extends React.Component {
13
30
  constructor(props, context) {
14
31
  super(props, context);
15
32
  var history = props.history;
16
33
  var callUrlChangedOnInit = props.callUrlChangedOnInit === true;
17
- createHistoryProxy(history, callUrlChangedOnInit);
34
+ createHistoryProxy(history, callUrlChangedOnInit, props.onUrlChange);
18
35
 
19
36
  if (props.connected) {
20
37
  props.connected(history);
@@ -16,7 +16,7 @@ function getInsId() {
16
16
  return insId;
17
17
  }
18
18
 
19
- export default function createHistoryProxy(history, callUrlChangedOnInit) {
19
+ export default function createHistoryProxy(history, callUrlChangedOnInit, onUrlChange) {
20
20
  if (!history.__insId) {
21
21
  history.__insId = getInsId();
22
22
  validInsId = history.__insId;
@@ -39,6 +39,7 @@ export default function createHistoryProxy(history, callUrlChangedOnInit) {
39
39
  // 防止CodeSandbox热加载模式下,多个history实例同时监听都有效
40
40
  // 只能让最新的一个history的监听起效
41
41
  if (history.__insId !== validInsId) return;
42
+ if (onUrlChange) onUrlChange(param, action);
42
43
  var modName = confMod.getModuleName();
43
44
  var urlChangedEvName = confMod.getUrlChangedEvName();
44
45
  var callInfo = historyProxy.getLatestCallInfo();
@@ -55,10 +56,10 @@ export default function createHistoryProxy(history, callUrlChangedOnInit) {
55
56
  } else {
56
57
  cc.setState(modName, param);
57
58
  }
58
- } //给300毫秒延迟,
59
- //既让concent有足够时间把该卸载的组件卸掉
60
- //也让concent有足够的时间把改挂的组件全部挂上(对于那种初次挂的组件)
61
- //然后在去刷新对应的cc组件
59
+ } // 给300毫秒延迟,
60
+ // 既让concent有足够时间把该卸载的组件卸掉
61
+ // 也让concent有足够的时间把该挂的组件全部挂上(对于那种初次挂的组件)
62
+ // 然后再去刷新对应的cc组件
62
63
 
63
64
 
64
65
  setTimeout(function () {
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "react-router-concent",
3
- "version": "2.2.5",
3
+ "version": "2.2.9",
4
4
  "description": "let using react-router more easily in concent",
5
- "main": "src/index.js",
5
+ "main": "dist/react-router-concent.js",
6
+ "types": "src/index.d.ts",
6
7
  "scripts": {
7
8
  "build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
8
9
  "build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
9
10
  "build:es": "rm -rf ./es/* && cp -r ./src/* ./es",
10
11
  "build:umd": "cross-env BABEL_ENV=rollup NODE_ENV=development rollup -c -o dist/react-router-concent.js",
11
12
  "build:umd:min": "cross-env BABEL_ENV=rollup NODE_ENV=production rollup -c -o dist/react-router-concent.min.js",
12
- "pub": "npm publish --registry=http://registry.npmjs.org",
13
+ "pub": "npm publish --registry=https://registry.npmjs.org",
13
14
  "test": "echo \"Error: no test specified\" && exit 1"
14
15
  },
15
16
  "repository": {
@@ -31,7 +32,8 @@
31
32
  "homepage": "https://github.com/concentjs/react-router-concent#readme",
32
33
  "peerDependencies": {
33
34
  "concent": "^2.4.0",
34
- "react": "^16.13.0"
35
+ "react": "^16.13.0",
36
+ "react-router-dom": "^5.0.1"
35
37
  },
36
38
  "devDependencies": {
37
39
  "@babel/cli": "^7.1.2",
@@ -57,11 +59,13 @@
57
59
  "enzyme": "^3.11.0",
58
60
  "enzyme-adapter-react-16": "^1.15.5",
59
61
  "es3ify": "^0.2.0",
60
- "eslint": "^4.19.1",
61
62
  "eslint-config-prettier": "^3.1.0",
62
- "eslint-plugin-import": "^2.14.0",
63
+ "eslint-config-standard": "^16.0.3",
64
+ "eslint-plugin-import": "^2.25.2",
65
+ "eslint-plugin-node": "^11.1.0",
63
66
  "eslint-plugin-prettier": "^3.0.0",
64
- "eslint-plugin-react": "^7.9.1",
67
+ "eslint-plugin-promise": "^5.1.1",
68
+ "eslint-plugin-react": "^7.26.1",
65
69
  "glob": "^7.1.1",
66
70
  "jest": "^26.6.3",
67
71
  "jest-dom": "^1.12.0",
@@ -83,6 +87,5 @@
83
87
  "set-value": "^3.0.2",
84
88
  "uglify-js": "3.5.8",
85
89
  "yargs-parser": "^20.2.1"
86
- },
87
- "dependencies": {}
90
+ }
88
91
  }
package/rollup.config.js CHANGED
@@ -5,7 +5,7 @@ import commonjs from 'rollup-plugin-commonjs'
5
5
  // import { uglify } from 'rollup-plugin-uglify'
6
6
  // 替代 uglify,解决 (plugin uglify) Error: Unexpected token: keyword «const»
7
7
  import { terser } from 'rollup-plugin-terser'
8
- import { eslint } from 'rollup-plugin-eslint';
8
+ // import { eslint } from 'rollup-plugin-eslint';
9
9
  import pkg from './package.json'
10
10
 
11
11
  const env = process.env.NODE_ENV;
@@ -44,9 +44,9 @@ const config = {
44
44
  'node_modules/react-is/index.js': ['isValidElementType'],
45
45
  }
46
46
  }),
47
- eslint({
48
- include: ['src/**/*.js'] // 需要检查的部分
49
- }),
47
+ // eslint({
48
+ // include: ['src/**/*.js'] // 需要检查的部分
49
+ // }),
50
50
  ]
51
51
  }
52
52
 
@@ -4,6 +4,20 @@ import createHistoryProxy from '../util/createHistoryProxy';
4
4
 
5
5
  var spanProps = { id: '__connect_router_span_by_fantasticsoul__', style: { display: 'none', width: 0, height: 0 } };
6
6
 
7
+ var withRouter = rrd.withRouter;
8
+ if (!withRouter) {
9
+ // v6 版本不再暴露 withRouter
10
+ withRouter = (Component) => {
11
+ const Wrapper = (props) => {
12
+ const history = rrd.useHistory();
13
+ return React.createElement(Component, { history, ...props });
14
+ };
15
+
16
+ return Wrapper;
17
+ };
18
+ }
19
+
20
+
7
21
  export default rrd.withRouter(
8
22
  class extends React.Component {
9
23
  constructor(props, context) {
@@ -11,7 +25,7 @@ export default rrd.withRouter(
11
25
  var history = props.history;
12
26
  var callUrlChangedOnInit = props.callUrlChangedOnInit === true;
13
27
 
14
- createHistoryProxy(history, callUrlChangedOnInit);
28
+ createHistoryProxy(history, callUrlChangedOnInit, props.onUrlChange);
15
29
  if (props.connected) {
16
30
  props.connected(history);
17
31
  }
package/src/index.d.ts CHANGED
@@ -9,6 +9,10 @@ export const ROUTER_MODULE: '$$CONCENT_ROUTER';
9
9
 
10
10
  type CRProps = {
11
11
  callUrlChangedOnInit?: boolean,
12
+ /**
13
+ * 相比 callUrlChangedOnInit,这个是实时的,没有延迟,方便做一些更方便的清理操作动作
14
+ */
15
+ onUrlChange?: (param: any, action: any) => void;
12
16
  connected?: (History: H.History) => void,
13
17
  };
14
18
  export class ConnectRouter extends Component<CRProps, {}> { }
@@ -35,7 +39,7 @@ export declare const history: {
35
39
  location: Location,
36
40
  };
37
41
 
38
- export function createHistoryProxy(history: H.History, callUrlChangedOnInit?: boolean): void;
42
+ export function createHistoryProxy(history: H.History, callUrlChangedOnInit?: boolean, onUrlChange?: CRProps['onUrlChange']): void;
39
43
  export function configureRoute(config?: { module?: string, onUrlChanged?: string }): void;
40
44
  export interface IRouterState<T extends any = any> {
41
45
  hash: string,
@@ -18,7 +18,7 @@ function getInsId() {
18
18
  return insId;
19
19
  }
20
20
 
21
- export default function createHistoryProxy(history, callUrlChangedOnInit) {
21
+ export default function createHistoryProxy(history, callUrlChangedOnInit, onUrlChange) {
22
22
 
23
23
  if (!history.__insId) {
24
24
  history.__insId = getInsId();
@@ -42,6 +42,7 @@ export default function createHistoryProxy(history, callUrlChangedOnInit) {
42
42
  // 防止CodeSandbox热加载模式下,多个history实例同时监听都有效
43
43
  // 只能让最新的一个history的监听起效
44
44
  if (history.__insId !== validInsId) return;
45
+ if (onUrlChange) onUrlChange(param, action);
45
46
 
46
47
  var modName = confMod.getModuleName();
47
48
  var urlChangedEvName = confMod.getUrlChangedEvName();
@@ -60,17 +61,17 @@ export default function createHistoryProxy(history, callUrlChangedOnInit) {
60
61
  }
61
62
  }
62
63
 
63
- //给300毫秒延迟,
64
- //既让concent有足够时间把该卸载的组件卸掉
65
- //也让concent有足够的时间把改挂的组件全部挂上(对于那种初次挂的组件)
66
- //然后在去刷新对应的cc组件
64
+ // 给300毫秒延迟,
65
+ // 既让concent有足够时间把该卸载的组件卸掉
66
+ // 也让concent有足够的时间把该挂的组件全部挂上(对于那种初次挂的组件)
67
+ // 然后再去刷新对应的cc组件
67
68
  setTimeout(function () {
68
69
  //onUrlChanged在组件初次挂载的时候也会执行
69
70
  if (_callUrlChangedOnInit) {
70
71
  cc.emit(urlChangedEvName, param, action, history);
71
72
  return;
72
73
  }
73
-
74
+
74
75
  var now = Date.now();
75
76
  cc.emit({
76
77
  name: urlChangedEvName, canPerform: ref => {
package/.eslintrc.js DELETED
@@ -1,29 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- parser: 'babel-eslint',
4
- extends: [
5
- 'eslint:recommended',
6
- 'plugin:react/recommended'
7
- ],
8
- settings: {
9
- react: {
10
- version: "detect"
11
- }
12
- },
13
- parserOptions: {
14
- ecmaVersion: 6,
15
- sourceType: "module",
16
- },
17
- env: {
18
- browser: true,
19
- es6: true,
20
- jest: true,
21
- },
22
- rules: {
23
- 'constructor-super': 0,
24
- camelcase: 0,
25
- 'no-unused-vars': 0,
26
- 'react/display-name': 0,
27
- 'react/prop-types': 0,
28
- }
29
- }