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 * as AllComponent from './test/pages/NamespaceComponent' 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 AllComponent.NamespaceComponent1({ 31 NamespaceComponent1Link1: $myState1, 32 NamespaceComponent1Link2: $myState2, 33 NamespaceComponent1Link3: $myState3, 34 NamespaceComponent1Link4: $myState4, 35 myVar: 100, 36 myVar2: 80 37 }) 38 AllComponent.NamespaceComponent1({ 39 NamespaceComponent1Link1: $myState1, 40 NamespaceComponent1Link2: $myState2, 41 NamespaceComponent1Link3: $myState3, 42 NamespaceComponent1Link4: $myState4, 43 myVar: 100, 44 myVar2: 80 45 }) 46 .width(100) 47 AllComponent.default({ 48 NamespaceComponent3Link1: $myState1, 49 NamespaceComponent3Link2: $myState2, 50 NamespaceComponent3Link3: $myState3, 51 NamespaceComponent3Link4: $myState4, 52 myVar: 100, 53 myVar2: 80 54 }) 55 AllComponent.default({ 56 NamespaceComponent3Link1: $myState1, 57 NamespaceComponent3Link2: $myState2, 58 NamespaceComponent3Link3: $myState3, 59 NamespaceComponent3Link4: $myState4, 60 myVar: 100, 61 myVar2: 80 62 }) 63 .height(200) 64 } 65 } 66} 67` 68 69exports.expectResult = 70`"use strict"; 71var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 72 if (k2 === undefined) k2 = k; 73 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); 74}) : (function(o, m, k, k2) { 75 if (k2 === undefined) k2 = k; 76 o[k2] = m[k]; 77})); 78var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { 79 Object.defineProperty(o, "default", { enumerable: true, value: v }); 80}) : function(o, v) { 81 o["default"] = v; 82}); 83var __importStar = (this && this.__importStar) || function (mod) { 84 if (mod && mod.__esModule) return mod; 85 var result = {}; 86 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); 87 __setModuleDefault(result, mod); 88 return result; 89}; 90var __importDefault = (this && this.__importDefault) || function (mod) { 91 return (mod && mod.__esModule) ? mod : { "default": mod }; 92}; 93Object.defineProperty(exports, "__esModule", { value: true }); 94const AllComponent = __importStar(require("./test/pages/NamespaceComponent")); 95const TsModule_1 = __importDefault(require("./test/pages/TsModule")); 96class ImportTest extends ViewPU { 97 constructor(parent, params, __localStorage, elmtId = -1) { 98 super(parent, __localStorage, elmtId); 99 this.__myState1 = new ObservedPropertyObjectPU(new TsModule_1.default(1).method(), this, "myState1"); 100 this.__myState2 = new ObservedPropertySimplePU(0, this, "myState2"); 101 this.__myState3 = new ObservedPropertySimplePU(false, this, "myState3"); 102 this.__myState4 = new ObservedPropertySimplePU('ImportTest', this, "myState4"); 103 this.setInitiallyProvidedValue(params); 104 } 105 setInitiallyProvidedValue(params) { 106 if (params.myState1 !== undefined) { 107 this.myState1 = params.myState1; 108 } 109 if (params.myState2 !== undefined) { 110 this.myState2 = params.myState2; 111 } 112 if (params.myState3 !== undefined) { 113 this.myState3 = params.myState3; 114 } 115 if (params.myState4 !== undefined) { 116 this.myState4 = params.myState4; 117 } 118 } 119 updateStateVars(params) { 120 } 121 purgeVariableDependenciesOnElmtId(rmElmtId) { 122 this.__myState1.purgeDependencyOnElmtId(rmElmtId); 123 this.__myState2.purgeDependencyOnElmtId(rmElmtId); 124 this.__myState3.purgeDependencyOnElmtId(rmElmtId); 125 this.__myState4.purgeDependencyOnElmtId(rmElmtId); 126 } 127 aboutToBeDeleted() { 128 this.__myState1.aboutToBeDeleted(); 129 this.__myState2.aboutToBeDeleted(); 130 this.__myState3.aboutToBeDeleted(); 131 this.__myState4.aboutToBeDeleted(); 132 SubscriberManager.Get().delete(this.id__()); 133 this.aboutToBeDeletedInternal(); 134 } 135 get myState1() { 136 return this.__myState1.get(); 137 } 138 set myState1(newValue) { 139 this.__myState1.set(newValue); 140 } 141 get myState2() { 142 return this.__myState2.get(); 143 } 144 set myState2(newValue) { 145 this.__myState2.set(newValue); 146 } 147 get myState3() { 148 return this.__myState3.get(); 149 } 150 set myState3(newValue) { 151 this.__myState3.set(newValue); 152 } 153 get myState4() { 154 return this.__myState4.get(); 155 } 156 set myState4(newValue) { 157 this.__myState4.set(newValue); 158 } 159 initialRender() { 160 this.observeComponentCreation((elmtId, isInitialRender) => { 161 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 162 Column.create(); 163 if (!isInitialRender) { 164 Column.pop(); 165 } 166 ViewStackProcessor.StopGetAccessRecording(); 167 }); 168 { 169 this.observeComponentCreation((elmtId, isInitialRender) => { 170 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 171 if (isInitialRender) { 172 ViewPU.create(new AllComponent.NamespaceComponent1(this, { 173 NamespaceComponent1Link1: this.__myState1, 174 NamespaceComponent1Link2: this.__myState2, 175 NamespaceComponent1Link3: this.__myState3, 176 NamespaceComponent1Link4: this.__myState4, 177 myVar: 100, 178 myVar2: 80 179 }, undefined, elmtId)); 180 } 181 else { 182 this.updateStateVarsOfChildByElmtId(elmtId, {}); 183 } 184 ViewStackProcessor.StopGetAccessRecording(); 185 }); 186 } 187 this.observeComponentCreation((elmtId, isInitialRender) => { 188 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 189 __Common__.create(); 190 __Common__.width(100); 191 if (!isInitialRender) { 192 __Common__.pop(); 193 } 194 ViewStackProcessor.StopGetAccessRecording(); 195 }); 196 { 197 this.observeComponentCreation((elmtId, isInitialRender) => { 198 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 199 if (isInitialRender) { 200 ViewPU.create(new AllComponent.NamespaceComponent1(this, { 201 NamespaceComponent1Link1: this.__myState1, 202 NamespaceComponent1Link2: this.__myState2, 203 NamespaceComponent1Link3: this.__myState3, 204 NamespaceComponent1Link4: this.__myState4, 205 myVar: 100, 206 myVar2: 80 207 }, undefined, elmtId)); 208 } 209 else { 210 this.updateStateVarsOfChildByElmtId(elmtId, {}); 211 } 212 ViewStackProcessor.StopGetAccessRecording(); 213 }); 214 } 215 __Common__.pop(); 216 { 217 this.observeComponentCreation((elmtId, isInitialRender) => { 218 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 219 if (isInitialRender) { 220 ViewPU.create(new AllComponent.default(this, { 221 NamespaceComponent3Link1: this.__myState1, 222 NamespaceComponent3Link2: this.__myState2, 223 NamespaceComponent3Link3: this.__myState3, 224 NamespaceComponent3Link4: this.__myState4, 225 myVar: 100, 226 myVar2: 80 227 }, undefined, elmtId)); 228 } 229 else { 230 this.updateStateVarsOfChildByElmtId(elmtId, {}); 231 } 232 ViewStackProcessor.StopGetAccessRecording(); 233 }); 234 } 235 this.observeComponentCreation((elmtId, isInitialRender) => { 236 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 237 __Common__.create(); 238 __Common__.height(200); 239 if (!isInitialRender) { 240 __Common__.pop(); 241 } 242 ViewStackProcessor.StopGetAccessRecording(); 243 }); 244 { 245 this.observeComponentCreation((elmtId, isInitialRender) => { 246 ViewStackProcessor.StartGetAccessRecordingFor(elmtId); 247 if (isInitialRender) { 248 ViewPU.create(new AllComponent.default(this, { 249 NamespaceComponent3Link1: this.__myState1, 250 NamespaceComponent3Link2: this.__myState2, 251 NamespaceComponent3Link3: this.__myState3, 252 NamespaceComponent3Link4: this.__myState4, 253 myVar: 100, 254 myVar2: 80 255 }, undefined, elmtId)); 256 } 257 else { 258 this.updateStateVarsOfChildByElmtId(elmtId, {}); 259 } 260 ViewStackProcessor.StopGetAccessRecording(); 261 }); 262 } 263 __Common__.pop(); 264 Column.pop(); 265 } 266 rerender() { 267 this.updateDirtyElements(); 268 } 269} 270ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); 271loadDocument(new ImportTest(undefined, {})); 272ViewStackProcessor.StopGetAccessRecording(); 273` 274