1/* 2 * Copyright (c) 2022 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 = ` 17import { AllStarComponent } from './test/pages/ExportStarComponent' 18import TsModule from './test/pages/TsModule' 19 20@Entry 21@Component 22struct ImportTest { 23 @State myState1: any = new TsModule(1).method(); 24 @State myState2: number = 0 25 @State myState3: boolean = false 26 @State myState4: string = 'ImportTest' 27 28 build() { 29 Column() { 30 AllStarComponent.ExportComponent({ 31 ExportComponent1Link1: $myState1, 32 ExportComponent1Link2: $myState2, 33 ExportComponent1Link3: $myState3, 34 ExportComponent1Link4: $myState4, 35 indexState1: { count: 1 }, 36 indexState2: 1, 37 indexState3: true, 38 indexState4: 'ExportComponent1' 39 }) 40 AllStarComponent.default({ 41 ExportComponent4Link1: $myState1, 42 ExportComponent4Link2: $myState2, 43 ExportComponent4Link3: $myState3, 44 ExportComponent4Link4: $myState4, 45 indexState1: { count: 1 }, 46 indexState2: 1, 47 indexState3: true, 48 indexState4: 'ExportComponent4' 49 }) 50 } 51 } 52} 53` 54 55exports.expectResult = 56`"use strict"; 57var __importDefault = (this && this.__importDefault) || function (mod) { 58 return (mod && mod.__esModule) ? mod : { "default": mod }; 59}; 60Object.defineProperty(exports, "__esModule", { value: true }); 61const ExportStarComponent_1 = require("./test/pages/ExportStarComponent"); 62const TsModule_1 = __importDefault(require("./test/pages/TsModule")); 63class ImportTest extends ViewPU { 64 constructor(parent, params, __localStorage, elmtId = -1) { 65 super(parent, __localStorage, elmtId); 66 this.__myState1 = new ObservedPropertyObjectPU(new TsModule_1.default(1).method(), this, "myState1"); 67 this.__myState2 = new ObservedPropertySimplePU(0, this, "myState2"); 68 this.__myState3 = new ObservedPropertySimplePU(false, this, "myState3"); 69 this.__myState4 = new ObservedPropertySimplePU('ImportTest', this, "myState4"); 70 this.setInitiallyProvidedValue(params); 71 } 72 setInitiallyProvidedValue(params) { 73 if (params.myState1 !== undefined) { 74 this.myState1 = params.myState1; 75 } 76 if (params.myState2 !== undefined) { 77 this.myState2 = params.myState2; 78 } 79 if (params.myState3 !== undefined) { 80 this.myState3 = params.myState3; 81 } 82 if (params.myState4 !== undefined) { 83 this.myState4 = params.myState4; 84 } 85 } 86 updateStateVars(params) { 87 } 88 purgeVariableDependenciesOnElmtId(rmElmtId) { 89 this.__myState1.purgeDependencyOnElmtId(rmElmtId); 90 this.__myState2.purgeDependencyOnElmtId(rmElmtId); 91 this.__myState3.purgeDependencyOnElmtId(rmElmtId); 92 this.__myState4.purgeDependencyOnElmtId(rmElmtId); 93 } 94 aboutToBeDeleted() { 95 this.__myState1.aboutToBeDeleted(); 96 this.__myState2.aboutToBeDeleted(); 97 this.__myState3.aboutToBeDeleted(); 98 this.__myState4.aboutToBeDeleted(); 99 SubscriberManager.Get().delete(this.id__()); 100 this.aboutToBeDeletedInternal(); 101 } 102 get myState1() { 103 return this.__myState1.get(); 104 } 105 set myState1(newValue) { 106 this.__myState1.set(newValue); 107 } 108 get myState2() { 109 return this.__myState2.get(); 110 } 111 set myState2(newValue) { 112 this.__myState2.set(newValue); 113 } 114 get myState3() { 115 return this.__myState3.get(); 116 } 117 set myState3(newValue) { 118 this.__myState3.set(newValue); 119 } 120 get myState4() { 121 return this.__myState4.get(); 122 } 123 set myState4(newValue) { 124 this.__myState4.set(newValue); 125 } 126 initialRender() { 127 this.observeComponentCreation((elmtId, isInitialRender) => { 128 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 129 Column.create(); 130 if (!isInitialRender) { 131 Column.pop(); 132 } 133 ViewStackProcessor.StopGetAccessRecording(); 134 }); 135 { 136 this.observeComponentCreation((elmtId, isInitialRender) => { 137 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 138 if (isInitialRender) { 139 ViewPU.create(new ExportStarComponent_1.AllStarComponent.ExportComponent(this, { 140 ExportComponent1Link1: this.__myState1, 141 ExportComponent1Link2: this.__myState2, 142 ExportComponent1Link3: this.__myState3, 143 ExportComponent1Link4: this.__myState4, 144 indexState1: { count: 1 }, 145 indexState2: 1, 146 indexState3: true, 147 indexState4: 'ExportComponent1' 148 }, undefined, elmtId)); 149 } 150 else { 151 this.updateStateVarsOfChildByElmtId(elmtId, {}); 152 } 153 ViewStackProcessor.StopGetAccessRecording(); 154 }); 155 } 156 { 157 this.observeComponentCreation((elmtId, isInitialRender) => { 158 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 159 if (isInitialRender) { 160 ViewPU.create(new ExportStarComponent_1.AllStarComponent.default(this, { 161 ExportComponent4Link1: this.__myState1, 162 ExportComponent4Link2: this.__myState2, 163 ExportComponent4Link3: this.__myState3, 164 ExportComponent4Link4: this.__myState4, 165 indexState1: { count: 1 }, 166 indexState2: 1, 167 indexState3: true, 168 indexState4: 'ExportComponent4' 169 }, undefined, elmtId)); 170 } 171 else { 172 this.updateStateVarsOfChildByElmtId(elmtId, {}); 173 } 174 ViewStackProcessor.StopGetAccessRecording(); 175 }); 176 } 177 Column.pop(); 178 } 179 rerender() { 180 this.updateDirtyElements(); 181 } 182} 183ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); 184loadDocument(new ImportTest(undefined, {})); 185ViewStackProcessor.StopGetAccessRecording(); 186` 187