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 MyComponent { 20 private test: string = 'Hello' 21 build() { 22 Column() { 23 Text(this.test) 24 ForEach( 25 weekNames, 26 (item, index) => { 27 Text(item) 28 .fontSize(10) 29 } 30 ) 31 }.width(100) 32 } 33}` 34 35exports.expectResult = 36`"use strict"; 37class MyComponent extends View { 38 constructor(compilerAssignedUniqueChildId, parent, params) { 39 super(compilerAssignedUniqueChildId, parent); 40 this.test = 'Hello'; 41 this.updateWithValueParams(params); 42 } 43 updateWithValueParams(params) { 44 if (params.test !== undefined) { 45 this.test = params.test; 46 } 47 } 48 aboutToBeDeleted() { 49 SubscriberManager.Get().delete(this.id()); 50 } 51 render() { 52 Column.create(); 53 Column.width(100); 54 Text.create(this.test); 55 Text.pop(); 56 ForEach.create("2", this, ObservedObject.GetRawObject(weekNames), (item, index) => { 57 Text.create(item); 58 Text.fontSize(10); 59 Text.pop(); 60 }); 61 ForEach.pop(); 62 Column.pop(); 63 } 64} 65loadDocument(new MyComponent("1", undefined, {})); 66` 67