Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
app-manage-console
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
app-manage-console
Commits
2cb70cf2
提交
2cb70cf2
authored
7月 11, 2018
作者:
vipcxj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
不再在切换菜单时unmodel对应模块model
上级
73bfc856
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
44 行增加
和
61 行删除
+44
-61
router.js
src/router.js
+39
-57
model.js
src/utils/model.js
+5
-4
没有找到文件。
src/router.js
浏览文件 @
2cb70cf2
...
...
@@ -8,7 +8,6 @@ import persistStore from 'redux-persist/lib/persistStore';
import
{
PersistGate
}
from
'redux-persist/integration/react'
;
import
{
REHYDRATE
}
from
'redux-persist/lib/constants'
;
import
isString
from
'lodash/isString'
;
import
get
from
'lodash/get'
;
import
config
from
'./utils/config'
;
import
{
getUser
,
isAuthed
,
hasDomain
,
histories
}
from
'./utils/auth'
;
import
{
processError
}
from
'./utils/error'
;
...
...
@@ -82,14 +81,11 @@ const moduleLeaveHook = (app, module) => {
const
models
=
(
app
.
_models
||
[]).
filter
(
m
=>
m
.
namespace
.
startsWith
(
`
${
module
.
name
}
/`
));
const
store
=
app
.
_store
;
models
.
forEach
((
m
)
=>
{
if
(
m
.
global
)
{
const
{
reducers
,
effects
}
=
m
;
if
((
reducers
&&
reducers
[
'@@exit'
])
||
(
effects
&&
effects
[
'@@exit'
]))
{
store
.
dispatch
({
type
:
`
${
m
.
namespace
}
/@@exit`
,
payload
:
module
});
}
}
else
{
app
.
unmodel
(
m
.
namespace
);
const
{
reducers
,
effects
}
=
m
;
if
((
reducers
&&
reducers
[
'@@exit'
])
||
(
effects
&&
effects
[
'@@exit'
]))
{
store
.
dispatch
({
type
:
`
${
m
.
namespace
}
/@@exit`
,
payload
:
module
});
}
store
.
dispatch
({
type
:
`
${
m
.
namespace
}
/@@reset`
});
});
};
...
...
@@ -97,11 +93,9 @@ const moduleEnterHook = (app, uid, module) => {
const
models
=
(
app
.
_models
||
[]).
filter
(
m
=>
m
.
namespace
.
startsWith
(
`
${
module
.
name
}
/`
));
const
store
=
app
.
_store
;
models
.
forEach
((
m
)
=>
{
if
(
m
.
global
)
{
const
{
reducers
,
effects
}
=
m
;
if
((
reducers
&&
reducers
[
'@@enter'
])
||
(
effects
&&
effects
[
'@@enter'
]))
{
store
.
dispatch
({
type
:
`
${
m
.
namespace
}
/@@enter`
,
payload
:
module
});
}
const
{
reducers
,
effects
}
=
m
;
if
((
reducers
&&
reducers
[
'@@enter'
])
||
(
effects
&&
effects
[
'@@enter'
]))
{
store
.
dispatch
({
type
:
`
${
m
.
namespace
}
/@@enter`
,
payload
:
module
});
}
});
histories
.
pushHistory
(
'module'
,
uid
,
module
);
...
...
@@ -126,7 +120,7 @@ const createRoutes = async (app, modules, groups, basePath) => {
fullPath
:
combinePath
(
basePath
,
name
),
name
:
showName
,
};
let
modelBundle
;
//
let modelBundle;
if
(
layout
.
route
)
{
// modelBundle = await import(`./models/main/modules/${layout.route}`);
// modelBundle = modelBundle.default;
...
...
@@ -151,15 +145,15 @@ const createRoutes = async (app, modules, groups, basePath) => {
}
else
{
route
.
component
=
Monk
;
}
let
model
;
if
(
modelBundle
)
{
model
=
{};
model
.
namespace
=
modelBundle
.
namespace
;
model
.
reducerEnterHook
=
modelBundle
.
reducers
&&
!!
modelBundle
.
reducers
[
'@@enter'
];
model
.
effectEnterHook
=
modelBundle
.
effects
&&
!!
modelBundle
.
effects
[
'@@enter'
];
model
.
reducerExitHook
=
modelBundle
.
reducers
&&
!!
modelBundle
.
reducers
[
'@@exit'
];
model
.
effectExitHook
=
modelBundle
.
effects
&&
!!
modelBundle
.
effects
[
'@@exit'
];
}
//
let model;
//
if (modelBundle) {
//
model = {};
//
model.namespace = modelBundle.namespace;
//
model.reducerEnterHook = modelBundle.reducers && !!modelBundle.reducers['@@enter'];
//
model.effectEnterHook = modelBundle.effects && !!modelBundle.effects['@@enter'];
//
model.reducerExitHook = modelBundle.reducers && !!modelBundle.reducers['@@exit'];
//
model.effectExitHook = modelBundle.effects && !!modelBundle.effects['@@exit'];
//
}
const
infoEx
=
{
...
info
,
path
:
route
.
fullPath
,
...
...
@@ -167,51 +161,39 @@ const createRoutes = async (app, modules, groups, basePath) => {
const
{
onLeave
}
=
route
;
if
(
onLeave
)
{
route
.
onLeave
=
(
preState
)
=>
{
if
(
get
(
preState
,
'location.pathname'
)
===
route
.
fullPath
)
{
moduleLeaveHook
(
app
,
infoEx
);
}
moduleLeaveHook
(
app
,
infoEx
);
onLeave
(
preState
);
};
}
else
{
route
.
onLeave
=
(
preState
)
=>
{
if
(
get
(
preState
,
'location.pathname'
)
===
route
.
fullPath
)
{
moduleLeaveHook
(
app
,
infoEx
);
}
route
.
onLeave
=
()
=>
{
moduleLeaveHook
(
app
,
infoEx
);
};
}
if
(
route
.
onEnter
)
{
const
onEnter
=
route
.
onEnter
;
route
.
onEnter
=
(
nextState
,
replace
,
cb
)
=>
{
if
(
get
(
nextState
,
'location.pathname'
)
===
route
.
fullPath
)
{
getUser
()
.
then
(
u
=>
u
.
id
)
.
then
(
uid
=>
moduleEnterHook
(
app
,
uid
,
infoEx
))
.
then
(()
=>
new
Promise
((
resolve
,
reject
)
=>
{
onEnter
(
nextState
,
replace
,
(
err
,
res
)
=>
{
if
(
err
)
{
reject
(
err
);
}
else
{
resolve
(
res
);
}
});
}))
.
then
(()
=>
cb
())
.
catch
(
err
=>
cb
(
err
));
}
else
{
return
onEnter
(
nextState
,
replace
,
cb
);
}
getUser
()
.
then
(
u
=>
u
.
id
)
.
then
(
uid
=>
moduleEnterHook
(
app
,
uid
,
infoEx
))
.
then
(()
=>
new
Promise
((
resolve
,
reject
)
=>
{
onEnter
(
nextState
,
replace
,
(
err
,
res
)
=>
{
if
(
err
)
{
reject
(
err
);
}
else
{
resolve
(
res
);
}
});
}))
.
then
(()
=>
cb
())
.
catch
(
err
=>
cb
(
err
));
};
}
else
{
route
.
onEnter
=
(
nextState
,
replace
,
cb
)
=>
{
if
(
get
(
nextState
,
'location.pathname'
)
===
route
.
fullPath
)
{
getUser
()
.
then
(
u
=>
u
.
id
)
.
then
(
uid
=>
moduleEnterHook
(
app
,
uid
,
infoEx
))
.
then
(()
=>
cb
())
.
catch
(
err
=>
cb
(
err
));
}
else
{
cb
();
}
getUser
()
.
then
(
u
=>
u
.
id
)
.
then
(
uid
=>
moduleEnterHook
(
app
,
uid
,
infoEx
))
.
then
(()
=>
cb
())
.
catch
(
err
=>
cb
(
err
));
};
}
routes
.
push
(
route
);
...
...
src/utils/model.js
浏览文件 @
2cb70cf2
...
...
@@ -5,9 +5,8 @@ import { shallowEqual } from './helper';
const
registerModel
=
(
app
,
model
)
=>
{
// noinspection JSUnresolvedVariable
if
(
app
.
_models
.
filter
(
m
=>
m
.
namespace
===
model
.
namespace
).
length
===
1
)
{
if
(
model
.
global
)
{
return
;
}
// eslint-disable-next-line no-console
console
.
warn
(
`model:
${
model
.
namespace
}
exist! unmodel it and remodeled.`
);
app
.
unmodel
(
model
.
namespace
);
}
app
.
model
(
model
);
...
...
@@ -115,7 +114,9 @@ const hackSubscriptions = (module, subscriptions) => {
export
const
hackModel
=
(
module
,
model
)
=>
{
model
=
{
...
model
};
model
.
namespace
=
`
${
module
}
/
${
model
.
namespace
}
`
;
model
.
initialState
=
model
.
state
;
model
.
initialState
=
{
...
model
.
state
};
model
.
reducers
=
model
.
reducers
||
{};
model
.
reducers
[
'@@reset'
]
=
()
=>
model
.
initialState
;
model
.
effects
=
hackEffects
(
module
,
model
.
effects
||
{});
model
.
subscriptions
=
hackSubscriptions
(
module
,
model
.
subscriptions
||
{});
return
model
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论