Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
app-manage-console
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
ReactNative
app-manage-console
Commits
39e575ac
提交
39e575ac
authored
7月 11, 2018
作者:
vipcxj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
解决redux-persist的hmr无限加载问题
上级
68d605b2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
7 行增加
和
15 行删除
+7
-15
index.js
src/index.js
+5
-5
router.js
src/router.js
+2
-10
没有找到文件。
src/index.js
浏览文件 @
39e575ac
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
import
dva
from
'dva'
;
import
dva
from
'dva'
;
import
createLoading
from
'dva-loading'
;
import
createLoading
from
'dva-loading'
;
import
moment
from
'moment'
;
import
moment
from
'moment'
;
// import { REHYDRATE } from 'redux-persist/lib/constants';
import
persistReducer
from
'redux-persist/lib/persistReducer'
;
import
persistReducer
from
'redux-persist/lib/persistReducer'
;
import
persistStore
from
'redux-persist/lib/persistStore'
;
import
storage
from
'redux-persist/lib/storage'
;
import
storage
from
'redux-persist/lib/storage'
;
import
{
getHistory
}
from
'./services/route'
;
import
{
getHistory
}
from
'./services/route'
;
import
{
initApp
}
from
'./data/app'
;
import
{
initApp
}
from
'./data/app'
;
...
@@ -17,17 +17,16 @@ moment.locale('zh-cn');
...
@@ -17,17 +17,16 @@ moment.locale('zh-cn');
const
persistConfig
=
{
const
persistConfig
=
{
key
:
'root'
,
key
:
'root'
,
debug
:
process
.
env
.
NODE_ENV
===
'development'
,
storage
,
storage
,
};
};
const
persistEnhancer
=
()
=>
createStore
=>
(
reducer
,
initialState
,
enhancer
)
=>
createStore
(
persistReducer
(
persistConfig
,
reducer
),
initialState
,
enhancer
);
// 1. Initialize
// 1. Initialize
const
app
=
dva
({
const
app
=
dva
({
history
:
getHistory
({
history
:
getHistory
({
basename
:
config
.
basename
,
basename
:
config
.
basename
,
}),
}),
extraEnhancers
:
[
persistEnhancer
()]
,
onReducer
:
reducer
=>
persistReducer
(
persistConfig
,
reducer
)
,
onError
(
error
)
{
onError
(
error
)
{
// eslint-disable-next-line no-console
// eslint-disable-next-line no-console
processError
(
error
);
processError
(
error
);
...
@@ -53,6 +52,7 @@ initApp(app).then(theApp => theApp.start('#root'));
...
@@ -53,6 +52,7 @@ initApp(app).then(theApp => theApp.start('#root'));
export
default
app
;
export
default
app
;
export
const
getStore
=
()
=>
{
export
const
getStore
=
()
=>
{
// eslint-disable-next-line no-underscore-dangle
return
app
.
_store
;
return
app
.
_store
;
};
};
export
const
createPersistor
=
theApp
=>
persistStore
(
theApp
.
_store
);
src/router.js
浏览文件 @
39e575ac
...
@@ -4,9 +4,7 @@ import PropTypes from 'prop-types';
...
@@ -4,9 +4,7 @@ import PropTypes from 'prop-types';
import
{
Router4Compat
as
Router
}
from
'react-router-4-compat'
;
import
{
Router4Compat
as
Router
}
from
'react-router-4-compat'
;
import
{
LocaleProvider
,
Spin
}
from
'antd'
;
import
{
LocaleProvider
,
Spin
}
from
'antd'
;
import
zhCN
from
'antd/lib/locale-provider/zh_CN'
;
import
zhCN
from
'antd/lib/locale-provider/zh_CN'
;
import
persistStore
from
'redux-persist/lib/persistStore'
;
import
{
PersistGate
}
from
'redux-persist/integration/react'
;
import
{
PersistGate
}
from
'redux-persist/integration/react'
;
import
{
REHYDRATE
}
from
'redux-persist/lib/constants'
;
import
isString
from
'lodash/isString'
;
import
isString
from
'lodash/isString'
;
import
config
from
'./utils/config'
;
import
config
from
'./utils/config'
;
import
{
getUser
,
isAuthed
,
hasDomain
,
histories
}
from
'./utils/auth'
;
import
{
getUser
,
isAuthed
,
hasDomain
,
histories
}
from
'./utils/auth'
;
...
@@ -15,9 +13,9 @@ import App from './routes/app';
...
@@ -15,9 +13,9 @@ import App from './routes/app';
import
{
getMenus
,
getModuleInfo
,
getModuleLayout
}
from
'./data/modules'
;
import
{
getMenus
,
getModuleInfo
,
getModuleLayout
}
from
'./data/modules'
;
import
{
bindModel
}
from
'./utils/model'
;
import
{
bindModel
}
from
'./utils/model'
;
import
Monk
from
'./routes/main/monk'
;
import
Monk
from
'./routes/main/monk'
;
import
{
createPersistor
}
from
'./index'
;
import
styles
from
'./index.css'
;
import
styles
from
'./index.css'
;
import
{
getStore
}
from
'./index'
;
const
Loading
=
<
Spin
size
=
"large"
className
=
{
styles
.
globalSpin
}
/>
;
const
Loading
=
<
Spin
size
=
"large"
className
=
{
styles
.
globalSpin
}
/>
;
...
@@ -309,7 +307,7 @@ function RouterConfig({ history, app }) {
...
@@ -309,7 +307,7 @@ function RouterConfig({ history, app }) {
});
});
}
}
return
(
return
(
<
PersistGate
persistor
=
{
persistStore
(
app
.
_store
)}
loading
=
{
Loading
}
>
<
PersistGate
persistor
=
{
createPersistor
(
app
)}
loading
=
{
Loading
}
>
<
LocaleProvider
locale
=
{
zhCN
}
>
<
LocaleProvider
locale
=
{
zhCN
}
>
<
Router
history
=
{
history
}
routes
=
{
routes
}
onError
=
{
processError
}
/
>
<
Router
history
=
{
history
}
routes
=
{
routes
}
onError
=
{
processError
}
/
>
<
/LocaleProvider
>
<
/LocaleProvider
>
...
@@ -323,9 +321,3 @@ RouterConfig.propTypes = {
...
@@ -323,9 +321,3 @@ RouterConfig.propTypes = {
};
};
export
default
RouterConfig
;
export
default
RouterConfig
;
if
(
module
.
hot
)
{
module
.
hot
.
accept
(()
=>
{
getStore
().
dispatch
({
type
:
REHYDRATE
});
});
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论