1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16exports.source = ` 17@Entry 18@Component 19struct HomeComponent { 20 private value1: string = "hello world 1" 21 private value2: string = "hello world 2" 22 private value3: string = "hello world 3" 23 private values: Array<Text> = [] 24 build() { 25 Column() { 26 ForEach(this.values, item => { 27 Column() { 28 if (this.value1) { 29 Text(this.value1) 30 } 31 if (this.value2) { 32 Text(this.value2) 33 } else { 34 Text(this.value3) 35 } 36 } 37 }, item => item) 38 ForEach(this.values, item => { 39 if (this.value1) { 40 Text(this.value1) 41 } 42 if (this.value2) { 43 Text(this.value2) 44 } else { 45 Text(this.value3) 46 } 47 }, item => item) 48 } 49 } 50}` 51 52exports.expectResult = 53`"use strict"; 54class HomeComponent extends View { 55 constructor(compilerAssignedUniqueChildId, parent, params) { 56 super(compilerAssignedUniqueChildId, parent); 57 this.value1 = "hello world 1"; 58 this.value2 = "hello world 2"; 59 this.value3 = "hello world 3"; 60 this.values = []; 61 this.updateWithValueParams(params); 62 } 63 updateWithValueParams(params) { 64 if (params.value1 !== undefined) { 65 this.value1 = params.value1; 66 } 67 if (params.value2 !== undefined) { 68 this.value2 = params.value2; 69 } 70 if (params.value3 !== undefined) { 71 this.value3 = params.value3; 72 } 73 if (params.values !== undefined) { 74 this.values = params.values; 75 } 76 } 77 aboutToBeDeleted() { 78 SubscriberManager.Get().delete(this.id()); 79 } 80 render() { 81 Column.create(); 82 ForEach.create("2", this, ObservedObject.GetRawObject(this.values), item => { 83 Column.create(); 84 If.create(); 85 if (this.value1) { 86 If.branchId(0); 87 Text.create(this.value1); 88 Text.pop(); 89 } 90 If.pop(); 91 If.create(); 92 if (this.value2) { 93 If.branchId(0); 94 Text.create(this.value2); 95 Text.pop(); 96 } 97 else { 98 If.branchId(1); 99 Text.create(this.value3); 100 Text.pop(); 101 } 102 If.pop(); 103 Column.pop(); 104 }, item => item); 105 ForEach.pop(); 106 ForEach.create("3", this, ObservedObject.GetRawObject(this.values), item => { 107 If.create(); 108 if (this.value1) { 109 If.branchId(0); 110 Text.create(this.value1); 111 Text.pop(); 112 } 113 If.pop(); 114 If.create(); 115 if (this.value2) { 116 If.branchId(0); 117 Text.create(this.value2); 118 Text.pop(); 119 } 120 else { 121 If.branchId(1); 122 Text.create(this.value3); 123 Text.pop(); 124 } 125 If.pop(); 126 }, item => item); 127 ForEach.pop(); 128 Column.pop(); 129 } 130} 131loadDocument(new HomeComponent("1", undefined, {})); 132` 133