react-router-concent 2.2.8 → 2.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -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})}));
@@ -25,7 +25,7 @@ export default rrd.withRouter(
25
25
  var history = props.history;
26
26
  var callUrlChangedOnInit = props.callUrlChangedOnInit === true;
27
27
 
28
- createHistoryProxy(history, callUrlChangedOnInit);
28
+ createHistoryProxy(history, callUrlChangedOnInit, props.onUrlChange);
29
29
  if (props.connected) {
30
30
  props.connected(history);
31
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 => {
@@ -31,7 +31,7 @@ export default rrd.withRouter(class extends React.Component {
31
31
  super(props, context);
32
32
  var history = props.history;
33
33
  var callUrlChangedOnInit = props.callUrlChangedOnInit === true;
34
- createHistoryProxy(history, callUrlChangedOnInit);
34
+ createHistoryProxy(history, callUrlChangedOnInit, props.onUrlChange);
35
35
 
36
36
  if (props.connected) {
37
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,6 +1,6 @@
1
1
  {
2
2
  "name": "react-router-concent",
3
- "version": "2.2.8",
3
+ "version": "2.2.9",
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",
@@ -25,7 +25,7 @@ export default rrd.withRouter(
25
25
  var history = props.history;
26
26
  var callUrlChangedOnInit = props.callUrlChangedOnInit === true;
27
27
 
28
- createHistoryProxy(history, callUrlChangedOnInit);
28
+ createHistoryProxy(history, callUrlChangedOnInit, props.onUrlChange);
29
29
  if (props.connected) {
30
30
  props.connected(history);
31
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 => {