Skip to content

Commit bef4e72

Browse files
committed
feat(wx-react): 增加对异步分包模式的支持
1 parent fda53c5 commit bef4e72

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

packages/wx-react/src/WxNormalComp.js

+35-29
Original file line numberDiff line numberDiff line change
@@ -59,39 +59,45 @@ export default function (compPath) {
5959
const uuid = geneUUID()
6060
this.data.diuu = uuid
6161

62-
const CompMySelf = wx._pageCompMaps[compPath]
63-
64-
renderPage(
65-
createElement(
66-
CompMySelf,
67-
{
68-
routerParams: paramsObj,
69-
diuu: uuid
70-
},
71-
),
72-
this
73-
)
74-
75-
const compInst = instanceManager.getCompInstByUUID(this.data.diuu)
76-
//如果组件还未初始化 didFocus方法,保证执行顺序为: didMount --> didFocus
77-
if (compInst.componentDidFocus) {
78-
const focusFunc = compInst.componentDidFocus
79-
const didMountFunc = compInst.componentDidMount
80-
81-
compInst.componentDidFocus = undefined
82-
compInst.componentDidMount = function () {
83-
didMountFunc && didMountFunc.call(compInst)
84-
focusFunc.call(compInst)
85-
compInst.componentDidFocus = focusFunc
86-
compInst.componentDidMount = didMountFunc
87-
}
88-
89-
}
62+
//const CompMySelf = wx._pageCompMaps[compPath]
63+
64+
wx._getCompByPath(compPath)
65+
.then((CompMySelf) => {
66+
67+
renderPage(
68+
createElement(
69+
CompMySelf,
70+
{
71+
routerParams: paramsObj,
72+
diuu: uuid
73+
},
74+
),
75+
this
76+
)
77+
78+
const compInst = instanceManager.getCompInstByUUID(this.data.diuu)
79+
//如果组件还未初始化 didFocus方法,保证执行顺序为: didMount --> didFocus
80+
if (compInst.componentDidFocus) {
81+
const focusFunc = compInst.componentDidFocus
82+
const didMountFunc = compInst.componentDidMount
83+
84+
compInst.componentDidFocus = undefined
85+
compInst.componentDidMount = function () {
86+
didMountFunc && didMountFunc.call(compInst)
87+
focusFunc.call(compInst)
88+
compInst.componentDidFocus = focusFunc
89+
compInst.componentDidMount = didMountFunc
90+
}
91+
92+
}
93+
94+
95+
})
9096
}
9197

9298
o.methods.onShow = function () {
9399
const compInst = instanceManager.getCompInstByUUID(this.data.diuu)
94-
compInst.componentDidFocus && unstable_batchedUpdates(() => {
100+
compInst && compInst.componentDidFocus && unstable_batchedUpdates(() => {
95101
compInst.componentDidFocus()
96102
})
97103
}

0 commit comments

Comments
 (0)