Skip to content

Commit 33209f2

Browse files
author
mayintao3
committed
chore: 标记需要被废弃的方法和逻辑
1 parent 2b6aebe commit 33209f2

File tree

2 files changed

+64
-47
lines changed
  • packages
    • taro-platform-harmony/src/runtime-ets/dom/element
    • taro-vite-runner/src/harmony/template

2 files changed

+64
-47
lines changed

packages/taro-platform-harmony/src/runtime-ets/dom/element/element.ts

+53-42
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ export class TaroElement<
3333
> extends TaroNode {
3434
public _innerHTML = ''
3535
public _nodeInfo: TaroAny = {
36-
layer: 0 // 渲染层级
36+
layer: 0, // 渲染层级
3737
}
3838

3939
public _hm_instance: TaroAny
4040
public weak_hm_instance: WeakRef<TaroAny>
4141
public use_weak_hm_instance: boolean = true
4242

43-
4443
public get hm_instance(): TaroAny {
4544
if (this.use_weak_hm_instance && this.weak_hm_instance) {
4645
return this.weak_hm_instance?.deref()
@@ -56,17 +55,16 @@ export class TaroElement<
5655
this._hm_instance = instance
5756
}
5857

59-
60-
public get _instance () {
58+
public get _instance() {
6159
return this.hm_instance
6260
}
6361

64-
public set _instance (value) {
62+
public set _instance(value) {
6563
this.hm_instance = value
6664
if (this._nodeInfo.aboutToAppear) {
6765
let task
6866
// eslint-disable-next-line no-cond-assign
69-
while (task = this._nodeInfo.aboutToAppear.shift()) {
67+
while ((task = this._nodeInfo.aboutToAppear.shift())) {
7068
task()
7169
}
7270
}
@@ -144,6 +142,10 @@ export class TaroElement<
144142

145143
// 混合开发的组件没办法自动更新,需要把父级的结点删掉新建
146144
// Current.nativeComponentNames会在render.ets中赋值
145+
/**
146+
* @deprecated
147+
* 这个逻辑分支在多线程中需要要去掉
148+
*/
147149
if (Current.nativeComponentNames?.includes(this.tagName)) {
148150
const idxOfRef = this.parentNode?.findIndex(this)
149151

@@ -159,7 +161,7 @@ export class TaroElement<
159161
id: this._nid,
160162
tagName: this.tagName,
161163
attribute: name,
162-
value
164+
value,
163165
})
164166
} else {
165167
const attributeTriggerValue: TaroAny = ATTRIBUTES_CALLBACK_TRIGGER_MAP[name]
@@ -266,7 +268,7 @@ export class TaroElement<
266268
if (!this._pseudo_before) {
267269
this._pseudo_before = new StyleSheet()
268270
}
269-
Object.keys(value).forEach(key => {
271+
Object.keys(value).forEach((key) => {
270272
this._pseudo_before!.hmStyle[key] = value[key]
271273
})
272274
} else {
@@ -281,7 +283,7 @@ export class TaroElement<
281283
if (!this._pseudo_after) {
282284
this._pseudo_after = new StyleSheet()
283285
}
284-
Object.keys(value).forEach(key => {
286+
Object.keys(value).forEach((key) => {
285287
this._pseudo_after!.hmStyle[key] = value[key]
286288
})
287289
} else {
@@ -299,15 +301,15 @@ export class TaroElement<
299301
if (!this._pseudo_class[name]) {
300302
this._pseudo_class[name] = new StyleSheet()
301303
}
302-
Object.keys(value).forEach(key => {
304+
Object.keys(value).forEach((key) => {
303305
this._pseudo_class[name]!.hmStyle[key] = value[key]
304306
})
305307
} else {
306308
this._pseudo_class[name] = null
307309
}
308310
}
309311

310-
get currentLayerNode () {
312+
get currentLayerNode() {
311313
if (!this._page) return null
312314
if (typeof this._page.tabBarCurrentIndex !== 'undefined') {
313315
this._page.layerNode ||= []
@@ -320,7 +322,7 @@ export class TaroElement<
320322
}
321323
}
322324

323-
get currentLayerParents () {
325+
get currentLayerParents() {
324326
if (!this._page) return null
325327
if (typeof this._page.tabBarCurrentIndex !== 'undefined') {
326328
this._page.layerParents ||= {}
@@ -337,7 +339,7 @@ export class TaroElement<
337339
// 1、appendChild的时候会判断是否需要设置层级
338340
// 2、taro-react的setProperty,在处理属性变化的时候,会判断是否需要设置层级
339341
// 3、removeChild的时候,会判断是否需要移除层级
340-
public setLayer (value: number) {
342+
public setLayer(value: number) {
341343
if (!this.parentNode) return // 没有父节点,不需要设置层级关系
342344

343345
const currentPage = getPageById(this.getAttribute('__fixed'))
@@ -359,7 +361,7 @@ export class TaroElement<
359361
generateLayerParentIds(_parentRecord, this)
360362
currentLayerParents[this.getStrNid()] = _parentRecord
361363
} else {
362-
const idx = currentLayerNode.childNodes.findIndex(n => n.getStrNid() === this.getStrNid())
364+
const idx = currentLayerNode.childNodes.findIndex((n) => n.getStrNid() === this.getStrNid())
363365
currentLayerNode.childNodes.splice(idx, 1)
364366
currentLayerNode.notifyDataDelete(idx)
365367

@@ -385,7 +387,7 @@ export class TaroElement<
385387
delete currentLayerParents[this.getStrNid()]
386388
this.setLayer(0)
387389
} else {
388-
Object.keys(currentLayerParents).forEach(fixedId => {
390+
Object.keys(currentLayerParents).forEach((fixedId) => {
389391
const parentIds = currentLayerParents[fixedId]
390392
if (parentIds[this.getStrNid()]) {
391393
// 需要移除fixedId
@@ -401,7 +403,7 @@ export class TaroElement<
401403
}
402404

403405
// 设置动画
404-
public setAnimation (playing) {
406+
public setAnimation(playing) {
405407
if (!this._instance) {
406408
if (!this._nodeInfo.aboutToAppear) {
407409
this._nodeInfo.aboutToAppear = []
@@ -436,41 +438,50 @@ export class TaroElement<
436438
this.parentNode.notifyDataDelete(idx)
437439

438440
// 下一帧播放,等实例被移除掉,再重新插入
439-
setTimeout(() => {
440-
// insert
441-
this.parentNode?.childNodes.splice(idx, 0, this)
442-
this.parentNode?.notifyDataAdd(idx)
443-
444-
// 执行动画
445-
if (playing) {
446-
this.playAnimation()
447-
}
448-
}, playing ? 0 : 100)
441+
setTimeout(
442+
() => {
443+
// insert
444+
this.parentNode?.childNodes.splice(idx, 0, this)
445+
this.parentNode?.notifyDataAdd(idx)
446+
447+
// 执行动画
448+
if (playing) {
449+
this.playAnimation()
450+
}
451+
},
452+
playing ? 0 : 100
453+
)
449454
}
450455
}
451456

452-
private playAnimation () {
457+
private playAnimation() {
453458
const {
454-
animationDuration = 0, animationDelay = 0, animationIterationCount = 1, animationName: keyframes,
455-
animationTimingFunction
459+
animationDuration = 0,
460+
animationDelay = 0,
461+
animationIterationCount = 1,
462+
animationName: keyframes,
463+
animationTimingFunction,
456464
} = this._st.hmStyle
457465

458466
if (keyframes) {
459467
let cur_percentage = 0
460-
this._instance.getUIContext()?.keyframeAnimateTo({
461-
delay: animationDelay,
462-
iterations: animationIterationCount,
463-
}, keyframes.map(item => {
464-
const duration = (item.percentage - cur_percentage) * animationDuration
465-
cur_percentage = item.percentage
466-
return {
467-
duration: duration,
468-
curve: item.event.animationTimingFunction || animationTimingFunction,
469-
event: () => {
470-
this._instance.overwriteStyle = item.event
468+
this._instance.getUIContext()?.keyframeAnimateTo(
469+
{
470+
delay: animationDelay,
471+
iterations: animationIterationCount,
472+
},
473+
keyframes.map((item) => {
474+
const duration = (item.percentage - cur_percentage) * animationDuration
475+
cur_percentage = item.percentage
476+
return {
477+
duration: duration,
478+
curve: item.event.animationTimingFunction || animationTimingFunction,
479+
event: () => {
480+
this._instance.overwriteStyle = item.event
481+
},
471482
}
472-
}
473-
}))
483+
})
484+
)
474485
}
475486
}
476487
}

packages/taro-vite-runner/src/harmony/template/render.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ export default class RenderParser extends BaseParser {
116116
if (meta.isPackage) {
117117
importList.push(`import ${meta.name} from '${meta.scriptPath}'`)
118118
} else {
119-
const nativePath = path.posix.relative(this.context.sourceDir, meta.scriptPath)
120-
.replace(/[\\/]+/g, '/').replace(/\.ets$/, '')
119+
const nativePath = path.posix
120+
.relative(this.context.sourceDir, meta.scriptPath)
121+
.replace(/[\\/]+/g, '/')
122+
.replace(/\.ets$/, '')
121123
importList.push(`import ${meta.name} from './${nativePath}'`)
122124
}
123125
})
@@ -280,13 +282,13 @@ export default class RenderParser extends BaseParser {
280282
name: 'StickySection',
281283
condition: `item.tagName === 'STICKY-SECTION'`,
282284
type: 'TaroViewElement',
283-
extra: '.reuseId(item._nid.toString())'
285+
extra: '.reuseId(item._nid.toString())',
284286
},
285287
{
286288
name: 'ListView',
287289
condition: `item.tagName === 'LIST-VIEW'`,
288290
type: 'TaroViewElement',
289-
extra: '.reuseId(item._nid.toString())'
291+
extra: '.reuseId(item._nid.toString())',
290292
},
291293
{
292294
name: 'View',
@@ -309,7 +311,7 @@ export default class RenderParser extends BaseParser {
309311
name,
310312
condition: `item.tagName === '${name.replace(new RegExp('(?<=.)([A-Z])', 'g'), '-$1').toUpperCase()}'`,
311313
args: [],
312-
fullArgument: 'item._attrs as TaroAny'
314+
fullArgument: 'item._attrs as TaroAny',
313315
})
314316
})
315317

@@ -395,6 +397,10 @@ export { createChildItem, createLazyChildren }`,
395397
}`
396398
}
397399

400+
/**
401+
* @deprecated
402+
* 这个方法在多线程中需要要去掉
403+
*/
398404
generateNativeComponentNamesInit() {
399405
if (this.context.nativeComponents.size === 0) return ''
400406
const commentsList: string[] = []

0 commit comments

Comments
 (0)