react-router-concent 2.2.7 → 2.2.10
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/react-router-concent.js +1 -1
- package/dist/react-router-concent.min.js +1 -1
- package/es/component/ConnectRouter.js +15 -1
- package/es/index.d.ts +5 -1
- package/es/util/createHistoryProxy.js +7 -6
- package/lib/component/ConnectRouter.js +18 -1
- package/lib/util/createHistoryProxy.js +6 -5
- package/package.json +11 -9
- package/rollup.config.js +4 -4
- package/src/component/ConnectRouter.js +15 -1
- package/src/index.d.ts +5 -1
- package/src/util/createHistoryProxy.js +7 -6
- package/.eslintrc.js +0 -29
@@ -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},
|
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},
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
}
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
} // 给300毫秒延迟,
|
60
|
+
// 既让concent有足够时间把该卸载的组件卸掉
|
61
|
+
// 也让concent有足够的时间把该挂的组件全部挂上(对于那种初次挂的组件)
|
62
|
+
// 然后再去刷新对应的cc组件
|
62
63
|
|
63
64
|
|
64
65
|
setTimeout(function () {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-router-concent",
|
3
|
-
"version": "2.2.
|
3
|
+
"version": "2.2.10",
|
4
4
|
"description": "let using react-router more easily in concent",
|
5
5
|
"main": "dist/react-router-concent.js",
|
6
6
|
"types": "src/index.d.ts",
|
@@ -10,7 +10,7 @@
|
|
10
10
|
"build:es": "rm -rf ./es/* && cp -r ./src/* ./es",
|
11
11
|
"build:umd": "cross-env BABEL_ENV=rollup NODE_ENV=development rollup -c -o dist/react-router-concent.js",
|
12
12
|
"build:umd:min": "cross-env BABEL_ENV=rollup NODE_ENV=production rollup -c -o dist/react-router-concent.min.js",
|
13
|
-
"pub": "npm publish --registry=
|
13
|
+
"pub": "npm publish --registry=https://registry.npmjs.org",
|
14
14
|
"test": "echo \"Error: no test specified\" && exit 1"
|
15
15
|
},
|
16
16
|
"repository": {
|
@@ -31,8 +31,9 @@
|
|
31
31
|
},
|
32
32
|
"homepage": "https://github.com/concentjs/react-router-concent#readme",
|
33
33
|
"peerDependencies": {
|
34
|
-
"concent": "
|
35
|
-
"react": "
|
34
|
+
"concent": ">=2.4.0",
|
35
|
+
"react": ">=16.8.0",
|
36
|
+
"react-router-dom": "^5.0.1"
|
36
37
|
},
|
37
38
|
"devDependencies": {
|
38
39
|
"@babel/cli": "^7.1.2",
|
@@ -58,11 +59,13 @@
|
|
58
59
|
"enzyme": "^3.11.0",
|
59
60
|
"enzyme-adapter-react-16": "^1.15.5",
|
60
61
|
"es3ify": "^0.2.0",
|
61
|
-
"eslint": "^4.19.1",
|
62
62
|
"eslint-config-prettier": "^3.1.0",
|
63
|
-
"eslint-
|
63
|
+
"eslint-config-standard": "^16.0.3",
|
64
|
+
"eslint-plugin-import": "^2.25.2",
|
65
|
+
"eslint-plugin-node": "^11.1.0",
|
64
66
|
"eslint-plugin-prettier": "^3.0.0",
|
65
|
-
"eslint-plugin-
|
67
|
+
"eslint-plugin-promise": "^5.1.1",
|
68
|
+
"eslint-plugin-react": "^7.26.1",
|
66
69
|
"glob": "^7.1.1",
|
67
70
|
"jest": "^26.6.3",
|
68
71
|
"jest-dom": "^1.12.0",
|
@@ -84,6 +87,5 @@
|
|
84
87
|
"set-value": "^3.0.2",
|
85
88
|
"uglify-js": "3.5.8",
|
86
89
|
"yargs-parser": "^20.2.1"
|
87
|
-
}
|
88
|
-
"dependencies": {}
|
90
|
+
}
|
89
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
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
}
|