Skip to content

Commit 0bd9e2f

Browse files
committedJul 16, 2019
fix(wx-react): 修改DiuuKey的判断方式
1 parent 18abf71 commit 0bd9e2f

File tree

6 files changed

+31
-18
lines changed

6 files changed

+31
-18
lines changed
 

‎packages/wx-react/miniprogram_dist/AllComponent.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export class BaseComponent {
8989
const allData = getObjSubData(this._r)
9090
const wxInst = instanceManager.getWxInstByUUID(diuu)
9191

92+
console.log('first wow:', allData, this)
9293
if (Object.keys(allData).length === 0) {
9394
recursionMount(this)
9495
} else {
@@ -123,6 +124,7 @@ export class BaseComponent {
123124
const topWX = styleUpdater ? styleUpdater.inst : this.getWxInst()
124125
let hasGprAdd = false
125126
topWX.groupSetData(() => {
127+
console.log('update wow:', updaterList)
126128
for(let i = 0; i < updaterList.length; i ++ ) {
127129
const {inst, data} = updaterList[i]
128130
if (!hasGprAdd) {
@@ -147,19 +149,17 @@ export class BaseComponent {
147149
*/
148150
updateWXInner(doneCb, updaterList, groupPromise) {
149151
const updatePros = []
152+
const updateObj = {}
150153
const children = this._c
151154
for (let i = 0; i < children.length; i++) {
152155
const childUuid = children[i]
153156
const child = instanceManager.getCompInstByUUID(childUuid)
154157

155158
if (child.firstRender !== FR_DONE && child.hocWrapped) {
156-
/**
157-
* 如果child 是由hoc包裹,由于hoc包裹的组件,并不直接对应微信实例,所以无法通过微信的ready的声明周期来执行
158-
* firstRender。不过此时微信小程序实例已经存在,所以可以直接调用setData方法
159-
*/
160159
const allSubData = getObjSubData(child._r)
161160
const wxInst = child.getWxInst()
162161

162+
// HOC 多次嵌套的情况,allSubData可能是{}
163163
if (Object.keys(allSubData).length === 0) {
164164
recursionMount(child)
165165
updatePros.push(P_R)
@@ -180,9 +180,13 @@ export class BaseComponent {
180180
updatePros.push(p)
181181
}
182182
} else if (child.firstRender !== FR_DONE && !child.hocWrapped) {
183-
// 新增普通节点,通过微信的ready 生命周期 触发firstRender
184-
const p = new Promise((resolve) => {
185-
child.firstRenderRes = resolve
183+
updateObj[`${child._keyPath}R`] = getObjSubData(child._r)
184+
185+
const p = new Promise(resolve => {
186+
groupPromise.then(() => {
187+
recursionMount(child)
188+
resolve()
189+
})
186190
})
187191
updatePros.push(p)
188192
} else if (child.shouldUpdate) {
@@ -209,6 +213,7 @@ export class BaseComponent {
209213

210214

211215
const cp = getChangePath(this._r, this._or)
216+
Object.assign(cp, updateObj)
212217
if (Object.keys(cp).length === 0) {
213218
updatePros.push(P_R)
214219
} else {
@@ -361,7 +366,7 @@ export class Component extends BaseComponent {
361366
while (true) {
362367
const pp = p._p
363368
if (pp.isPageComp || !p._isFirstEle) {
364-
const stylePath = p._stylePath
369+
const stylePath = `${p._keyPath}style`
365370
setDeepData(pp, newOutStyle, stylePath)
366371

367372
const diuu = pp.__diuu__

‎packages/wx-react/miniprogram_dist/WxCPTComp.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ export default function () {
2323

2424
ready() {
2525
const compInst = instanceManager.getCompInstByUUID(this.data.diuu)
26-
// 一般情况下 CPTComp 都是无状态组件, 但是由于HOC的存在, 对于HOC包裹的组件, 需要主动firstUpdateUI
27-
if (!compInst.firstRender && !compInst.stateless) {
28-
compInst.firstUpdateUI()
29-
}
26+
3027
},
3128

3229
detached() {

‎packages/wx-react/miniprogram_dist/WxNormalComp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function (CompMySelf, RNApp) {
2626

2727
ready() {
2828
const compInst = instanceManager.getCompInstByUUID(this.data.diuu)
29-
if (!compInst.firstRender) {
29+
if (compInst.isPageComp) {
3030
compInst.firstUpdateUI()
3131
}
3232
},

‎packages/wx-react/miniprogram_dist/getObjSubData.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import instanceManager from "./InstanceManager";
1010
import {HOCKEY, FR_PENDING} from './util'
1111

1212
function isDiuuKey(key) {
13-
return key.startsWith("DIUU") && key.length === 9
13+
// TODO 更加精确的方式??
14+
return key.includes('DIUU')
1415
}
1516

1617
function getListSubData(list) {

‎packages/wx-react/miniprogram_dist/render.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export default function render(vnode, parentInst, parentContext, data, oldData,
209209
// 当Ua的key由Ka --> Kb 的时候, 那么组件变为Ub负责来渲染这一块, 故而需要给予Ub对应的数据
210210
// 对于明确且唯一的key, 小程序和React处理是一致的
211211
const vIndex = data[datakey].v.length - 1
212-
render(subVnode, parentInst, parentContext, subData, oldSubDataKeyMap[subKey], `${dataPath}.${datakey}.v.${vIndex}`)
212+
render(subVnode, parentInst, parentContext, subData, oldSubDataKeyMap[subKey], `${dataPath}.${datakey}.v.[${vIndex}]`)
213213
}
214214
} else {
215215
let oldSubData = null
@@ -640,7 +640,7 @@ function reportSubStyleToOuter(parentDiuu, subVnode, inst, parentInst, dataPath)
640640
const styleValue = 'display: none;'
641641
setStyleData(parentInst, outStyleKey, styleValue, dataPath)
642642
inst._myOutStyle = styleValue
643-
inst._stylePath = `${dataPath}.${outStyleKey}`
643+
inst._keyPath = `${dataPath}.${parentDiuu}`
644644
return
645645
}
646646

@@ -655,7 +655,7 @@ function reportSubStyleToOuter(parentDiuu, subVnode, inst, parentInst, dataPath)
655655
const styleValue = inst._r[styleKey]
656656

657657
inst._myOutStyle = styleValue
658-
inst._stylePath = `${dataPath}.${outStyleKey}`
658+
inst._keyPath = `${dataPath}.${parentDiuu}`
659659

660660

661661
inst._r[styleKey] = DEFAULTCONTAINERSTYLE

‎packages/wx-react/miniprogram_dist/util.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,17 @@ export function setDeepData(inst, v, path) {
7474
let tmpObj = inst
7575
for (let i = 0; i < arr.length - 1; i++) {
7676
const sk = arr[i]
77-
tmpObj = tmpObj[sk]
77+
78+
if (sk.charAt(0) === '[' && sk.charAt(sk.length - 1) === ']') {
79+
const index = Number(sk.substring(1, sk.length - 1))
80+
if (!Number.isNaN(index)) {
81+
tmpObj = tmpObj[index]
82+
} else {
83+
tmpObj = tmpObj[sk]
84+
}
85+
} else {
86+
tmpObj = tmpObj[sk]
87+
}
7888
}
7989

8090
const endk = arr[arr.length - 1]

0 commit comments

Comments
 (0)
Please sign in to comment.