From 2ff592dfaf5b1402b7b438680be73fe1ba0493c8 Mon Sep 17 00:00:00 2001 From: sqsyqqy Date: Tue, 5 Sep 2023 10:22:43 +0800 Subject: [PATCH] =?UTF-8?q?ArkTS=E9=80=82=E9=85=8D?= 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 | 8 ++--- .../improve-application-response.md | 35 +++++++++---------- .../reduce-view-nesting-levels.md | 14 ++++---- 3 files changed, 26 insertions(+), 31 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 5c74b68967..daad5a9965 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 @@ -100,11 +100,9 @@ struct Index { // 运算任务异步处理 private computeTaskAsync() { - new Promise((resolved, rejected) => { - setTimeout(() => { // 这里使用setTimeout来实现异步延迟运行 - this.computeTask(); - }, 1000) - }) + setTimeout(() => { // 这里使用setTimeout来实现异步延迟运行 + this.computeTask(); + }, 1000) } } ``` \ No newline at end of file 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 98466b306c..b21b235961 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 @@ -40,7 +40,7 @@ struct ImageExample1 { ```typescript @Entry @Component -struct ImageExample1 { +struct ImageExample2 { build() { Column() { Row() { @@ -78,7 +78,7 @@ function computeTask(arr: string[]): string[] { @Entry @Component -struct AspectRatioExample { +struct AspectRatioExample3 { @State children: string[] = ['1', '2', '3', '4', '5', '6']; aboutToAppear() { @@ -88,8 +88,7 @@ struct AspectRatioExample { async computeTaskInTaskPool() { const param = this.children.slice(); let task = new taskpool.Task(computeTask, param); - // @ts-ignore - this.children = await taskpool.execute(task); + await taskpool.execute(task); } build() { @@ -105,7 +104,7 @@ struct AspectRatioExample { ```typescript @Entry @Component -struct AspectRatioExample { +struct AspectRatioExample4 { @State private children: string[] = ['1', '2', '3', '4', '5', '6']; private count: number = 0; @@ -123,11 +122,9 @@ struct AspectRatioExample { } computeTaskAsync() { - new Promise((resolved, rejected) => { - setTimeout(() => { // 这里使用setTimeout来实现异步延迟运行 - this.computeTask(); - }, 1000) - }) + setTimeout(() => { // 这里使用setTimeout来实现异步延迟运行 + this.computeTask(); + }, 1000) } build() { @@ -149,7 +146,7 @@ struct AspectRatioExample { ```typescript @Entry @Component -struct StackExample { +struct StackExample5 { @State isVisible : boolean = false; build() { @@ -178,7 +175,7 @@ struct StackExample { ```typescript @Entry @Component -struct StackExample { +struct StackExample6 { @State isVisible : boolean = false; build() { @@ -211,8 +208,8 @@ struct StackExample { ```typescript @Entry @Component -struct MyComponent { - @State arr: number[] = Array.from(Array(10000), (v,k) =>k); +struct MyComponent7 { + @State arr: number[] = Array.from(Array(10000), (v,k) =>k); build() { List() { ForEach(this.arr, (item: number) => { @@ -235,8 +232,8 @@ class BasicDataSource implements IDataSource { return 0 } - public getData(index: number): any { - return undefined + public getData(index: number): string { + return '' } registerDataChangeListener(listener: DataChangeListener): void { @@ -286,13 +283,13 @@ class BasicDataSource implements IDataSource { } class MyDataSource extends BasicDataSource { - private dataArray: string[] = Array.from(Array(10000), (v, k) => k.toString()); + private dataArray: string[] = Array.from(Array(10000), (v, k) => k.toString()); public totalCount(): number { return this.dataArray.length } - public getData(index: number): any { + public getData(index: number): string { return this.dataArray[index] } @@ -318,7 +315,7 @@ struct MyComponent { ListItem() { Text(item).fontSize(20).margin({ left: 10 }) } - }, item => item) + }, (item:string) => item) } } } 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 d2df662443..c9337880df 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 @@ -9,13 +9,13 @@ ```typescript @Entry @Component -struct AspectRatioExample { - @State children: Number[] = Array.from(Array(900), (v, k) => k); +struct AspectRatioExample12 { + @State children: Number[] = Array.from(Array(900), (v, k) => k); build() { Scroll() { Grid() { - ForEach(this.children, (item) => { + ForEach(this.children, (item:Number[]) => { GridItem() { Stack() { Stack() { @@ -25,7 +25,7 @@ struct AspectRatioExample { } } } - }, item => item) + }, (item:string) => item) } .columnsTemplate('1fr 1fr 1fr 1fr') .columnsGap(0) @@ -41,17 +41,17 @@ struct AspectRatioExample { ```typescript @Entry @Component -struct AspectRatioExample { +struct AspectRatioExample11 { @State children: Number[] = Array.from(Array(900), (v, k) => k); build() { Scroll() { Grid() { - ForEach(this.children, (item) => { + ForEach(this.children, (item:Number[]) => { GridItem() { Text(item.toString()) } - }, item => item) + }, (item:string) => item) } .columnsTemplate('1fr 1fr 1fr 1fr') .columnsGap(0) -- GitLab