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