@@ -19,6 +19,8 @@ import {
19
19
getRealOc ,
20
20
invokeWillUnmount ,
21
21
recursionFirstFlushWX ,
22
+ getShowUpdaterMap ,
23
+ HIDDEN_STYLE ,
22
24
recursionMountOrUpdate
23
25
} from './util'
24
26
import reactUpdate from './ReactUpdate'
@@ -142,6 +144,23 @@ export class BaseComponent {
142
144
return inst . getDeepComp ( )
143
145
}
144
146
147
+ /**
148
+ * 如果是hocWrapped组件,一直往外追溯
149
+ * @returns {* }
150
+ */
151
+ getTopComp ( ) {
152
+ if ( this . hocWrapped ) {
153
+ let p = this . _p
154
+ while ( p . hocWrapped ) {
155
+ p = p . _p
156
+ }
157
+
158
+ return instanceManager . getCompInstByUUID ( p . __diuu__ )
159
+ } else {
160
+ return this
161
+ }
162
+ }
163
+
145
164
getWxInst ( ) {
146
165
let diuu = null
147
166
@@ -164,11 +183,49 @@ export class BaseComponent {
164
183
*/
165
184
firstUpdateWX ( ) {
166
185
const deepComp = this . getDeepComp ( )
167
-
168
186
if ( ! deepComp || Object . keys ( deepComp . _r ) . length === 0 ) {
187
+ // 页面组件render null
169
188
recursionMountOrUpdate ( this )
189
+ return
190
+ }
191
+
192
+
193
+ const pageWxInst = this . getWxInst ( )
194
+ const comps = [ ]
195
+ // 收集下一次groupSetData的实例
196
+ deepComp . _c . forEach ( item => {
197
+ const child = instanceManager . getCompInstByUUID ( item )
198
+ if ( child . _myOutStyle ) {
199
+ const childComp = child . getDeepComp ( )
200
+ comps . push ( childComp )
201
+ }
202
+ } )
203
+
204
+ if ( comps . length === 0 ) {
205
+ pageWxInst . setData ( {
206
+ _r : deepComp . _r
207
+ } , ( ) => {
208
+ recursionMountOrUpdate ( this )
209
+ } )
170
210
} else {
171
- recursionFirstFlushWX ( this , this . getWxInst ( ) , [ deepComp ] )
211
+ const styleKey = deepComp . firstStyleKey
212
+ const styleValue = deepComp . _r [ styleKey ]
213
+ const pageShowUpdater = {
214
+ inst : pageWxInst ,
215
+ data : {
216
+ [ `_r.${ styleKey } ` ] : styleValue
217
+ }
218
+ }
219
+ pageWxInst . setData ( {
220
+ _r : {
221
+ ...deepComp . _r ,
222
+ [ deepComp . firstStyleKey ] : `${ styleValue } ${ HIDDEN_STYLE } `
223
+ }
224
+ } , ( ) => {
225
+ recursionFirstFlushWX ( this , pageWxInst , comps , [ pageShowUpdater ] , ( ) => {
226
+ recursionMountOrUpdate ( this )
227
+ } )
228
+ } )
172
229
}
173
230
}
174
231
@@ -178,30 +235,10 @@ export class BaseComponent {
178
235
* @param styleUpdater 上报样式的updater
179
236
*/
180
237
updateWX ( cb , styleUpdater ) {
181
-
182
- // 页面组件特殊处理
183
- let topComp = null
184
- if ( this . isPageComp ) {
185
- const dc = this . getDeepComp ( )
186
- if ( ! dc || Object . keys ( dc . _r ) . length === 0 ) {
187
- this . getWxInst ( ) . setData ( {
188
- _r : { }
189
- } , ( ) => {
190
- recursionMountOrUpdate ( this )
191
- cb && cb ( )
192
- } )
193
- return
194
- } else {
195
- topComp = dc
196
- }
197
- } else {
198
- topComp = this
199
- }
200
-
201
238
const flushList = [ ]
202
239
const firstFlushList = [ ]
203
240
204
- topComp . updateWXInner ( flushList , firstFlushList )
241
+ this . updateWXInner ( flushList , firstFlushList )
205
242
206
243
if ( styleUpdater ) {
207
244
flushList . push ( styleUpdater )
@@ -213,17 +250,26 @@ export class BaseComponent {
213
250
return
214
251
}
215
252
253
+ const showUpdaterMap = getShowUpdaterMap ( firstFlushList )
254
+
216
255
/// groupSetData 来优化多次setData
217
256
218
257
const topWX = styleUpdater ? styleUpdater . inst : this . getWxInst ( )
219
258
topWX . groupSetData ( ( ) => {
220
- console . log ( 'update wow:' , flushList )
221
259
for ( let i = 0 ; i < flushList . length ; i ++ ) {
222
260
const { inst, data} = flushList [ i ]
223
261
262
+ const updater = showUpdaterMap . get ( inst )
263
+ if ( updater ) {
264
+ Object . assign ( data , updater . hiddenData )
265
+ }
266
+
224
267
if ( i === 0 ) {
225
268
inst . setData ( data , ( ) => {
226
- recursionFirstFlushWX ( this , topWX , firstFlushList , cb )
269
+ recursionFirstFlushWX ( this , topWX , firstFlushList , Array . from ( showUpdaterMap . values ( ) ) , ( ) => {
270
+ recursionMountOrUpdate ( this )
271
+ cb && cb ( )
272
+ } )
227
273
} )
228
274
} else {
229
275
inst . setData ( data )
@@ -241,7 +287,44 @@ export class BaseComponent {
241
287
* @param firstFlushList
242
288
*/
243
289
updateWXInner ( flushList , firstFlushList ) {
244
- if ( this . firstRender !== FR_DONE ) {
290
+ let shouldTraversalChild = false
291
+ if ( this . isPageComp ) {
292
+ const dc = this . getDeepComp ( )
293
+ if ( ! dc || Object . keys ( dc . _r ) . length === 0 ) {
294
+ // 页面组件 render null
295
+ flushList . push ( {
296
+ inst : this . getWxInst ( ) ,
297
+ data : {
298
+ _r : { }
299
+ }
300
+ } )
301
+ return
302
+ }
303
+
304
+
305
+ if ( this . firstRender === FR_DONE && ! this . shouldUpdate ) {
306
+ return
307
+ }
308
+
309
+ if ( this instanceof HocComponent ) {
310
+ shouldTraversalChild = true
311
+ } else {
312
+ const cp = getChangePath ( this . _r , this . _or )
313
+ // _or 不在有用
314
+ this . _or = { }
315
+
316
+ if ( Object . keys ( cp ) . length === 0 ) {
317
+ shouldTraversalChild = true
318
+ } else {
319
+ const wxInst = this . getWxInst ( )
320
+ flushList . push ( {
321
+ inst : wxInst ,
322
+ data : cp
323
+ } )
324
+ shouldTraversalChild = true
325
+ }
326
+ }
327
+ } else if ( this . firstRender !== FR_DONE ) {
245
328
if ( this . _myOutStyle === false ) {
246
329
return
247
330
}
@@ -253,8 +336,6 @@ export class BaseComponent {
253
336
return
254
337
}
255
338
256
- let shouldTraversalChild = false
257
-
258
339
if ( this instanceof HocComponent ) {
259
340
shouldTraversalChild = true
260
341
} else {
@@ -273,22 +354,21 @@ export class BaseComponent {
273
354
} )
274
355
shouldTraversalChild = true
275
356
} else {
276
- const top = this . topExistWx ( ) //this.getDeepComp()
357
+ const top = this . topExistWx ( )
277
358
firstFlushList . push ( top )
278
359
}
279
360
}
280
361
}
362
+ }
281
363
282
- if ( shouldTraversalChild ) {
283
- const children = this . _c
284
- for ( let i = 0 ; i < children . length ; i ++ ) {
285
- const childUuid = children [ i ]
286
- const child = instanceManager . getCompInstByUUID ( childUuid )
364
+ if ( shouldTraversalChild ) {
365
+ const children = this . _c
366
+ for ( let i = 0 ; i < children . length ; i ++ ) {
367
+ const childUuid = children [ i ]
368
+ const child = instanceManager . getCompInstByUUID ( childUuid )
287
369
288
- child . updateWXInner ( flushList , firstFlushList )
289
- }
370
+ child . updateWXInner ( flushList , firstFlushList )
290
371
}
291
-
292
372
}
293
373
}
294
374
}
@@ -440,6 +520,7 @@ export class Component extends BaseComponent {
440
520
/* eslint-disable-next-line */
441
521
while ( true ) {
442
522
const pp = p . _p
523
+ p . _myOutStyle = newOutStyle
443
524
if ( pp . isPageComp || ! p . _isFirstEle || p . _TWFBStylePath ) {
444
525
const stylePath = p . _TWFBStylePath || `${ p . _keyPath } style`
445
526
setDeepData ( pp , newOutStyle , stylePath )
0 commit comments