107ac75b1Sopenharmony_ci/* 207ac75b1Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 307ac75b1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 407ac75b1Sopenharmony_ci * you may not use this file except in compliance with the License. 507ac75b1Sopenharmony_ci * You may obtain a copy of the License at 607ac75b1Sopenharmony_ci * 707ac75b1Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 807ac75b1Sopenharmony_ci * 907ac75b1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1007ac75b1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1107ac75b1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1207ac75b1Sopenharmony_ci * See the License for the specific language governing permissions and 1307ac75b1Sopenharmony_ci * limitations under the License. 1407ac75b1Sopenharmony_ci */ 1507ac75b1Sopenharmony_ci 1607ac75b1Sopenharmony_ciexports.source = ` 1707ac75b1Sopenharmony_ciimport { ClassB as ClassA } from './test/pages/import@Observed' 1807ac75b1Sopenharmony_ci@Component 1907ac75b1Sopenharmony_cistruct ViewA { 2007ac75b1Sopenharmony_ci label: string = 'ViewA1' 2107ac75b1Sopenharmony_ci @ObjectLink a: ClassA 2207ac75b1Sopenharmony_ci 2307ac75b1Sopenharmony_ci build() { 2407ac75b1Sopenharmony_ci Row() { 2507ac75b1Sopenharmony_ci Button('ViewA'+ JSON.stringify(this.label) + 'this.a.c='+JSON.stringify(this.a.c)) 2607ac75b1Sopenharmony_ci .onClick(() => { 2707ac75b1Sopenharmony_ci this.a.c += 1 2807ac75b1Sopenharmony_ci }) 2907ac75b1Sopenharmony_ci }.margin({ top: 10 }) 3007ac75b1Sopenharmony_ci } 3107ac75b1Sopenharmony_ci} 3207ac75b1Sopenharmony_ci 3307ac75b1Sopenharmony_ci@Entry 3407ac75b1Sopenharmony_ci@Component 3507ac75b1Sopenharmony_cistruct ViewB { 3607ac75b1Sopenharmony_ci @State arrA: ClassA[] = [new ClassA(0), new ClassA(0)] 3707ac75b1Sopenharmony_ci 3807ac75b1Sopenharmony_ci build() { 3907ac75b1Sopenharmony_ci Column() { 4007ac75b1Sopenharmony_ci ForEach(this.arrA, (item) => { 4107ac75b1Sopenharmony_ci ViewA({ label: JSON.stringify(item.id), a: item }) 4207ac75b1Sopenharmony_ci }, (item) => item.id.toString()) 4307ac75b1Sopenharmony_ci ViewA({ label: JSON.stringify(this.arrA[0]), a: this.arrA[0] }) 4407ac75b1Sopenharmony_ci ViewA({ label: JSON.stringify(this.arrA[this.arrA.length - 1]), a: this.arrA[this.arrA.length - 1] }) 4507ac75b1Sopenharmony_ci 4607ac75b1Sopenharmony_ci Button('ViewB: reset array') 4707ac75b1Sopenharmony_ci .margin({ top: 10 }) 4807ac75b1Sopenharmony_ci .onClick(() => { 4907ac75b1Sopenharmony_ci this.arrA = [new ClassA(0), new ClassA(0)] 5007ac75b1Sopenharmony_ci }) 5107ac75b1Sopenharmony_ci Button('ViewB: push') 5207ac75b1Sopenharmony_ci .margin({ top: 10 }) 5307ac75b1Sopenharmony_ci .onClick(() => { 5407ac75b1Sopenharmony_ci this.arrA.push(new ClassA(0)) 5507ac75b1Sopenharmony_ci }) 5607ac75b1Sopenharmony_ci Button('ViewB: shift') 5707ac75b1Sopenharmony_ci .margin({ top: 10 }) 5807ac75b1Sopenharmony_ci .onClick(() => { 5907ac75b1Sopenharmony_ci this.arrA.shift() 6007ac75b1Sopenharmony_ci }) 6107ac75b1Sopenharmony_ci }.width('100%') 6207ac75b1Sopenharmony_ci } 6307ac75b1Sopenharmony_ci} 6407ac75b1Sopenharmony_ci` 6507ac75b1Sopenharmony_ci 6607ac75b1Sopenharmony_ciexports.expectResult = 6707ac75b1Sopenharmony_ci`"use strict"; 6807ac75b1Sopenharmony_ciObject.defineProperty(exports, "__esModule", { value: true }); 6907ac75b1Sopenharmony_cilet __generate__Id = 0; 7007ac75b1Sopenharmony_cifunction generateId() { 7107ac75b1Sopenharmony_ci return "import@Observed_" + ++__generate__Id; 7207ac75b1Sopenharmony_ci} 7307ac75b1Sopenharmony_ciconst import_Observed_1 = require("./test/pages/import@Observed"); 7407ac75b1Sopenharmony_ciclass ViewA extends View { 7507ac75b1Sopenharmony_ci constructor(compilerAssignedUniqueChildId, parent, params, localStorage) { 7607ac75b1Sopenharmony_ci super(compilerAssignedUniqueChildId, parent, localStorage); 7707ac75b1Sopenharmony_ci this.label = 'ViewA1'; 7807ac75b1Sopenharmony_ci this.__a = new SynchedPropertyNesedObject(params.a, this, "a"); 7907ac75b1Sopenharmony_ci this.updateWithValueParams(params); 8007ac75b1Sopenharmony_ci } 8107ac75b1Sopenharmony_ci updateWithValueParams(params) { 8207ac75b1Sopenharmony_ci if (params.label !== undefined) { 8307ac75b1Sopenharmony_ci this.label = params.label; 8407ac75b1Sopenharmony_ci } 8507ac75b1Sopenharmony_ci this.__a.set(params.a); 8607ac75b1Sopenharmony_ci } 8707ac75b1Sopenharmony_ci aboutToBeDeleted() { 8807ac75b1Sopenharmony_ci this.__a.aboutToBeDeleted(); 8907ac75b1Sopenharmony_ci SubscriberManager.Get().delete(this.id()); 9007ac75b1Sopenharmony_ci } 9107ac75b1Sopenharmony_ci get a() { 9207ac75b1Sopenharmony_ci return this.__a.get(); 9307ac75b1Sopenharmony_ci } 9407ac75b1Sopenharmony_ci render() { 9507ac75b1Sopenharmony_ci Row.create(); 9607ac75b1Sopenharmony_ci Row.margin({ top: 10 }); 9707ac75b1Sopenharmony_ci Button.createWithLabel('ViewA' + JSON.stringify(this.label) + 'this.a.c=' + JSON.stringify(this.a.c)); 9807ac75b1Sopenharmony_ci Button.onClick(() => { 9907ac75b1Sopenharmony_ci this.a.c += 1; 10007ac75b1Sopenharmony_ci }); 10107ac75b1Sopenharmony_ci Button.pop(); 10207ac75b1Sopenharmony_ci Row.pop(); 10307ac75b1Sopenharmony_ci } 10407ac75b1Sopenharmony_ci} 10507ac75b1Sopenharmony_ciclass ViewB extends View { 10607ac75b1Sopenharmony_ci constructor(compilerAssignedUniqueChildId, parent, params, localStorage) { 10707ac75b1Sopenharmony_ci super(compilerAssignedUniqueChildId, parent, localStorage); 10807ac75b1Sopenharmony_ci this.__arrA = new ObservedPropertyObject([new import_Observed_1.ClassB(0), new import_Observed_1.ClassB(0)], this, "arrA"); 10907ac75b1Sopenharmony_ci this.updateWithValueParams(params); 11007ac75b1Sopenharmony_ci } 11107ac75b1Sopenharmony_ci updateWithValueParams(params) { 11207ac75b1Sopenharmony_ci if (params.arrA !== undefined) { 11307ac75b1Sopenharmony_ci this.arrA = params.arrA; 11407ac75b1Sopenharmony_ci } 11507ac75b1Sopenharmony_ci } 11607ac75b1Sopenharmony_ci aboutToBeDeleted() { 11707ac75b1Sopenharmony_ci this.__arrA.aboutToBeDeleted(); 11807ac75b1Sopenharmony_ci SubscriberManager.Get().delete(this.id()); 11907ac75b1Sopenharmony_ci } 12007ac75b1Sopenharmony_ci get arrA() { 12107ac75b1Sopenharmony_ci return this.__arrA.get(); 12207ac75b1Sopenharmony_ci } 12307ac75b1Sopenharmony_ci set arrA(newValue) { 12407ac75b1Sopenharmony_ci this.__arrA.set(newValue); 12507ac75b1Sopenharmony_ci } 12607ac75b1Sopenharmony_ci render() { 12707ac75b1Sopenharmony_ci Column.create(); 12807ac75b1Sopenharmony_ci Column.width('100%'); 12907ac75b1Sopenharmony_ci ForEach.create("3", this, ObservedObject.GetRawObject(this.arrA), (item) => { 13007ac75b1Sopenharmony_ci let earlierCreatedChild_2 = (this && this.findChildById) ? this.findChildById("2") : undefined; 13107ac75b1Sopenharmony_ci if (earlierCreatedChild_2 == undefined) { 13207ac75b1Sopenharmony_ci View.create(new ViewA("2", this, { label: JSON.stringify(item.id), a: item })); 13307ac75b1Sopenharmony_ci } 13407ac75b1Sopenharmony_ci else { 13507ac75b1Sopenharmony_ci earlierCreatedChild_2.updateWithValueParams({ 13607ac75b1Sopenharmony_ci label: JSON.stringify(item.id), a: item 13707ac75b1Sopenharmony_ci }); 13807ac75b1Sopenharmony_ci View.create(earlierCreatedChild_2); 13907ac75b1Sopenharmony_ci } 14007ac75b1Sopenharmony_ci }, (item) => item.id.toString()); 14107ac75b1Sopenharmony_ci ForEach.pop(); 14207ac75b1Sopenharmony_ci let earlierCreatedChild_4 = (this && this.findChildById) ? this.findChildById("4") : undefined; 14307ac75b1Sopenharmony_ci if (earlierCreatedChild_4 == undefined) { 14407ac75b1Sopenharmony_ci View.create(new ViewA("4", this, { label: JSON.stringify(this.arrA[0]), a: this.arrA[0] })); 14507ac75b1Sopenharmony_ci } 14607ac75b1Sopenharmony_ci else { 14707ac75b1Sopenharmony_ci earlierCreatedChild_4.updateWithValueParams({ 14807ac75b1Sopenharmony_ci label: JSON.stringify(this.arrA[0]), a: this.arrA[0] 14907ac75b1Sopenharmony_ci }); 15007ac75b1Sopenharmony_ci View.create(earlierCreatedChild_4); 15107ac75b1Sopenharmony_ci } 15207ac75b1Sopenharmony_ci let earlierCreatedChild_5 = (this && this.findChildById) ? this.findChildById("5") : undefined; 15307ac75b1Sopenharmony_ci if (earlierCreatedChild_5 == undefined) { 15407ac75b1Sopenharmony_ci View.create(new ViewA("5", this, { label: JSON.stringify(this.arrA[this.arrA.length - 1]), a: this.arrA[this.arrA.length - 1] })); 15507ac75b1Sopenharmony_ci } 15607ac75b1Sopenharmony_ci else { 15707ac75b1Sopenharmony_ci earlierCreatedChild_5.updateWithValueParams({ 15807ac75b1Sopenharmony_ci label: JSON.stringify(this.arrA[this.arrA.length - 1]), a: this.arrA[this.arrA.length - 1] 15907ac75b1Sopenharmony_ci }); 16007ac75b1Sopenharmony_ci View.create(earlierCreatedChild_5); 16107ac75b1Sopenharmony_ci } 16207ac75b1Sopenharmony_ci Button.createWithLabel('ViewB: reset array'); 16307ac75b1Sopenharmony_ci Button.margin({ top: 10 }); 16407ac75b1Sopenharmony_ci Button.onClick(() => { 16507ac75b1Sopenharmony_ci this.arrA = [new import_Observed_1.ClassB(0), new import_Observed_1.ClassB(0)]; 16607ac75b1Sopenharmony_ci }); 16707ac75b1Sopenharmony_ci Button.pop(); 16807ac75b1Sopenharmony_ci Button.createWithLabel('ViewB: push'); 16907ac75b1Sopenharmony_ci Button.margin({ top: 10 }); 17007ac75b1Sopenharmony_ci Button.onClick(() => { 17107ac75b1Sopenharmony_ci this.arrA.push(new import_Observed_1.ClassB(0)); 17207ac75b1Sopenharmony_ci }); 17307ac75b1Sopenharmony_ci Button.pop(); 17407ac75b1Sopenharmony_ci Button.createWithLabel('ViewB: shift'); 17507ac75b1Sopenharmony_ci Button.margin({ top: 10 }); 17607ac75b1Sopenharmony_ci Button.onClick(() => { 17707ac75b1Sopenharmony_ci this.arrA.shift(); 17807ac75b1Sopenharmony_ci }); 17907ac75b1Sopenharmony_ci Button.pop(); 18007ac75b1Sopenharmony_ci Column.pop(); 18107ac75b1Sopenharmony_ci } 18207ac75b1Sopenharmony_ci} 18307ac75b1Sopenharmony_ciloadDocument(new ViewB("1", undefined, {})); 18407ac75b1Sopenharmony_ci` 185