From 2bbe7e3e9bb7db6c1708363f8cf801af9a80aff3 Mon Sep 17 00:00:00 2001 From: sqsyqqy Date: Mon, 4 Sep 2023 14:59:24 +0800 Subject: [PATCH] =?UTF-8?q?ArkTS=E5=91=8A=E8=AD=A6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sqsyqqy --- .../improve-application-cold-start-speed.md | 2 +- .../improve-application-response.md | 16 ++++++++-------- .../reduce-animation-frame-loss.md | 6 +++--- .../reduce-view-nesting-levels.md | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/zh-cn/application-dev/performance/improve-application-startup-and-response/improve-application-cold-start-speed.md b/zh-cn/application-dev/performance/improve-application-startup-and-response/improve-application-cold-start-speed.md index dbb87f4612..9a8575e537 100644 --- a/zh-cn/application-dev/performance/improve-application-startup-and-response/improve-application-cold-start-speed.md +++ b/zh-cn/application-dev/performance/improve-application-startup-and-response/improve-application-cold-start-speed.md @@ -69,7 +69,7 @@ OpenHarmony的应用冷启动过程大致可分成以下四个阶段:应用进 aboutToAppear函数会在创建自定义组件实例后,页面绘制之前执行,以下代码在aboutToAppear中对耗时长的计算任务进行了异步处理,避免在该接口执行该耗时操作,不阻塞页面绘制。 -```javascript +```typescript @Entry @Component struct Index { diff --git a/zh-cn/application-dev/performance/improve-application-startup-and-response/improve-application-response.md b/zh-cn/application-dev/performance/improve-application-startup-and-response/improve-application-response.md index acd7a634b8..4762a0b23c 100644 --- a/zh-cn/application-dev/performance/improve-application-startup-and-response/improve-application-response.md +++ b/zh-cn/application-dev/performance/improve-application-startup-and-response/improve-application-response.md @@ -13,7 +13,7 @@ OpenHarmony提供的Image组件默认生效异步加载特性,当应用在页面上展示一批本地图片的时候,会先显示空白占位块,当图片在其他线程加载完毕后,再替换占位块。这样图片加载就可以不阻塞页面的显示,给用户带来良好的交互体验。因此,只在加载图片耗时比较短的情况下建议下述代码。 -```javascript +```typescript @Entry @Component struct ImageExample1 { @@ -37,7 +37,7 @@ struct ImageExample1 { 建议:在加载图片的耗时比较短的时候,通过异步加载的效果会大打折扣,建议配置Image的syncLoad属性。 -```javascript +```typescript @Entry @Component struct ImageExample1 { @@ -63,7 +63,7 @@ struct ImageExample1 { OpenHarmony提供了[TaskPool线程池](../../reference/apis/js-apis-taskpool.md),相比worker线程,TaskPool提供了任务优先级设置、线程池自动管理机制,示例如下: -```javascript +```typescript import taskpool from '@ohos.taskpool'; @Concurrent @@ -102,7 +102,7 @@ struct AspectRatioExample { 以下代码展示了将一个长时间执行的非UI任务通过Promise声明成异步任务,主线程可以先进行用户反馈-绘制初始页面。等主线程空闲时,再执行异步任务。等到异步任务运行完毕后,重绘相关组件刷新页面。 -```javascript +```typescript @Entry @Component struct AspectRatioExample { @@ -146,7 +146,7 @@ struct AspectRatioExample { 以下代码的Text('New Page')组件被状态变量isVisible控制,isVisible为true时创建,false时销毁。当isVisible发生变化时,Stack容器内的所有组件都会刷新: -```javascript +```typescript @Entry @Component struct StackExample { @@ -175,7 +175,7 @@ struct StackExample { 建议:对于这种受状态变量控制的组件,在if外套一层容器,减少刷新范围。 -```javascript +```typescript @Entry @Component struct StackExample { @@ -208,7 +208,7 @@ struct StackExample { 反例:this.arr中的每一项元素都被初始化和加载,数组中的元素有10000个,主线程执行耗时长。 -```javascript +```typescript @Entry @Component struct MyComponent { @@ -227,7 +227,7 @@ struct MyComponent { 建议:这种情况下用LazyForEach替换ForEach,LazyForEach一般只加载可见的元素,避免一次性初始化和加载所有元素。 -```javascript +```typescript class BasicDataSource implements IDataSource { private listeners: DataChangeListener[] = [] diff --git a/zh-cn/application-dev/performance/reduce-frame-loss-and-frame-freezing/reduce-animation-frame-loss.md b/zh-cn/application-dev/performance/reduce-frame-loss-and-frame-freezing/reduce-animation-frame-loss.md index caaf5d2281..2aed2e3f3f 100644 --- a/zh-cn/application-dev/performance/reduce-frame-loss-and-frame-freezing/reduce-animation-frame-loss.md +++ b/zh-cn/application-dev/performance/reduce-frame-loss-and-frame-freezing/reduce-animation-frame-loss.md @@ -6,7 +6,7 @@ 反例:应用使用了自定义动画,动画曲线计算过程很容易引起UI线程高负载,易导致丢帧。 -```javascript +```typescript @Entry @Component struct AttrAnimationExample { @@ -56,7 +56,7 @@ struct AttrAnimationExample { 建议:通过系统提供的属性动效API实现上述动效功能。 -```javascript +```typescript @Entry @Component struct AttrAnimationExample { @@ -96,7 +96,7 @@ struct AttrAnimationExample { 建议:通过系统提供的显式动效API实现上述动效功能。 -```javascript +```typescript @Entry @Component struct AnimateToExample { diff --git a/zh-cn/application-dev/performance/reduce-frame-loss-and-frame-freezing/reduce-view-nesting-levels.md b/zh-cn/application-dev/performance/reduce-frame-loss-and-frame-freezing/reduce-view-nesting-levels.md index ab4cf3697a..bfe962fc77 100644 --- a/zh-cn/application-dev/performance/reduce-frame-loss-and-frame-freezing/reduce-view-nesting-levels.md +++ b/zh-cn/application-dev/performance/reduce-frame-loss-and-frame-freezing/reduce-view-nesting-levels.md @@ -6,7 +6,7 @@ 反例:使用了Grid来实现一个网格,但是在外层套了3层stack容器,导致组件刷新和渲染耗时长。 -```javascript +```typescript @Entry @Component struct AspectRatioExample { @@ -38,7 +38,7 @@ struct AspectRatioExample { 建议:通过减少冗余的Stack容器嵌套,每个GridItem的组件数比上面少了3个,缩短了组件刷新与渲染耗时。 -```javascript +```typescript // xxx.ets @Entry @Component -- GitLab