Skip to content

Commit

Permalink
feat(wx-react): 增加对异步分包模式的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
ykforerlang committed Jan 2, 2020
1 parent fda53c5 commit bef4e72
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions packages/wx-react/src/WxNormalComp.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,39 +59,45 @@ export default function (compPath) {
const uuid = geneUUID()
this.data.diuu = uuid

const CompMySelf = wx._pageCompMaps[compPath]

renderPage(
createElement(
CompMySelf,
{
routerParams: paramsObj,
diuu: uuid
},
),
this
)

const compInst = instanceManager.getCompInstByUUID(this.data.diuu)
//如果组件还未初始化 didFocus方法,保证执行顺序为: didMount --> didFocus
if (compInst.componentDidFocus) {
const focusFunc = compInst.componentDidFocus
const didMountFunc = compInst.componentDidMount

compInst.componentDidFocus = undefined
compInst.componentDidMount = function () {
didMountFunc && didMountFunc.call(compInst)
focusFunc.call(compInst)
compInst.componentDidFocus = focusFunc
compInst.componentDidMount = didMountFunc
}

}
//const CompMySelf = wx._pageCompMaps[compPath]

wx._getCompByPath(compPath)
.then((CompMySelf) => {

renderPage(
createElement(
CompMySelf,
{
routerParams: paramsObj,
diuu: uuid
},
),
this
)

const compInst = instanceManager.getCompInstByUUID(this.data.diuu)
//如果组件还未初始化 didFocus方法,保证执行顺序为: didMount --> didFocus
if (compInst.componentDidFocus) {
const focusFunc = compInst.componentDidFocus
const didMountFunc = compInst.componentDidMount

compInst.componentDidFocus = undefined
compInst.componentDidMount = function () {
didMountFunc && didMountFunc.call(compInst)
focusFunc.call(compInst)
compInst.componentDidFocus = focusFunc
compInst.componentDidMount = didMountFunc
}

}


})
}

o.methods.onShow = function () {
const compInst = instanceManager.getCompInstByUUID(this.data.diuu)
compInst.componentDidFocus && unstable_batchedUpdates(() => {
compInst && compInst.componentDidFocus && unstable_batchedUpdates(() => {
compInst.componentDidFocus()
})
}
Expand Down

0 comments on commit bef4e72

Please sign in to comment.