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, paramsLambda = undefined) { 65 super(parent, __localStorage, elmtId); 66 if (typeof paramsLambda === "function") { 67 this.paramsGenerator_ = paramsLambda; 68 } 69 this.__myState1 = new ObservedPropertyObjectPU(new TsModule_1.default(1).method(), this, "myState1"); 70 this.__myState2 = new ObservedPropertySimplePU(0, this, "myState2"); 71 this.__myState3 = new ObservedPropertySimplePU(false, this, "myState3"); 72 this.__myState4 = new ObservedPropertySimplePU('ImportTest', this, "myState4"); 73 this.setInitiallyProvidedValue(params); 74 } 75 setInitiallyProvidedValue(params) { 76 if (params.myState1 !== undefined) { 77 this.myState1 = params.myState1; 78 } 79 if (params.myState2 !== undefined) { 80 this.myState2 = params.myState2; 81 } 82 if (params.myState3 !== undefined) { 83 this.myState3 = params.myState3; 84 } 85 if (params.myState4 !== undefined) { 86 this.myState4 = params.myState4; 87 } 88 } 89 updateStateVars(params) { 90 } 91 purgeVariableDependenciesOnElmtId(rmElmtId) { 92 this.__myState1.purgeDependencyOnElmtId(rmElmtId); 93 this.__myState2.purgeDependencyOnElmtId(rmElmtId); 94 this.__myState3.purgeDependencyOnElmtId(rmElmtId); 95 this.__myState4.purgeDependencyOnElmtId(rmElmtId); 96 } 97 aboutToBeDeleted() { 98 this.__myState1.aboutToBeDeleted(); 99 this.__myState2.aboutToBeDeleted(); 100 this.__myState3.aboutToBeDeleted(); 101 this.__myState4.aboutToBeDeleted(); 102 SubscriberManager.Get().delete(this.id__()); 103 this.aboutToBeDeletedInternal(); 104 } 105 get myState1() { 106 return this.__myState1.get(); 107 } 108 set myState1(newValue) { 109 this.__myState1.set(newValue); 110 } 111 get myState2() { 112 return this.__myState2.get(); 113 } 114 set myState2(newValue) { 115 this.__myState2.set(newValue); 116 } 117 get myState3() { 118 return this.__myState3.get(); 119 } 120 set myState3(newValue) { 121 this.__myState3.set(newValue); 122 } 123 get myState4() { 124 return this.__myState4.get(); 125 } 126 set myState4(newValue) { 127 this.__myState4.set(newValue); 128 } 129 initialRender() { 130 this.observeComponentCreation2((elmtId, isInitialRender) => { 131 Column.create(); 132 }, Column); 133 { 134 this.observeComponentCreation2((elmtId, isInitialRender) => { 135 if (isInitialRender) { 136 let paramsLambda = () => { 137 return { 138 ExportComponent1Link1: this.myState1, 139 ExportComponent1Link2: this.myState2, 140 ExportComponent1Link3: this.myState3, 141 ExportComponent1Link4: this.myState4, 142 indexState1: { count: 1 }, 143 indexState2: 1, 144 indexState3: true, 145 indexState4: 'ExportComponent1' 146 }; 147 }; 148 ViewPU.create(new ExportStarComponent_1.AllStarComponent.ExportComponent(this, { 149 ExportComponent1Link1: this.__myState1, 150 ExportComponent1Link2: this.__myState2, 151 ExportComponent1Link3: this.__myState3, 152 ExportComponent1Link4: this.__myState4, 153 indexState1: { count: 1 }, 154 indexState2: 1, 155 indexState3: true, 156 indexState4: 'ExportComponent1' 157 }, undefined, elmtId, paramsLambda)); 158 } 159 else { 160 this.updateStateVarsOfChildByElmtId(elmtId, {}); 161 } 162 }, null); 163 } 164 { 165 this.observeComponentCreation2((elmtId, isInitialRender) => { 166 if (isInitialRender) { 167 let paramsLambda = () => { 168 return { 169 ExportComponent4Link1: this.myState1, 170 ExportComponent4Link2: this.myState2, 171 ExportComponent4Link3: this.myState3, 172 ExportComponent4Link4: this.myState4, 173 indexState1: { count: 1 }, 174 indexState2: 1, 175 indexState3: true, 176 indexState4: 'ExportComponent4' 177 }; 178 }; 179 ViewPU.create(new ExportStarComponent_1.AllStarComponent.default(this, { 180 ExportComponent4Link1: this.__myState1, 181 ExportComponent4Link2: this.__myState2, 182 ExportComponent4Link3: this.__myState3, 183 ExportComponent4Link4: this.__myState4, 184 indexState1: { count: 1 }, 185 indexState2: 1, 186 indexState3: true, 187 indexState4: 'ExportComponent4' 188 }, undefined, elmtId, paramsLambda)); 189 } 190 else { 191 this.updateStateVarsOfChildByElmtId(elmtId, {}); 192 } 193 }, null); 194 } 195 Column.pop(); 196 } 197 rerender() { 198 this.updateDirtyElements(); 199 } 200} 201ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); 202loadDocument(new ImportTest(undefined, {})); 203ViewStackProcessor.StopGetAccessRecording(); 204` 205