• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, paramsLambda = undefined) {
98        super(parent, __localStorage, elmtId);
99        if (typeof paramsLambda === "function") {
100            this.paramsGenerator_ = paramsLambda;
101        }
102        this.__myState1 = new ObservedPropertyObjectPU(new TsModule_1.default(1).method(), this, "myState1");
103        this.__myState2 = new ObservedPropertySimplePU(0, this, "myState2");
104        this.__myState3 = new ObservedPropertySimplePU(false, this, "myState3");
105        this.__myState4 = new ObservedPropertySimplePU('ImportTest', this, "myState4");
106        this.setInitiallyProvidedValue(params);
107    }
108    setInitiallyProvidedValue(params) {
109        if (params.myState1 !== undefined) {
110            this.myState1 = params.myState1;
111        }
112        if (params.myState2 !== undefined) {
113            this.myState2 = params.myState2;
114        }
115        if (params.myState3 !== undefined) {
116            this.myState3 = params.myState3;
117        }
118        if (params.myState4 !== undefined) {
119            this.myState4 = params.myState4;
120        }
121    }
122    updateStateVars(params) {
123    }
124    purgeVariableDependenciesOnElmtId(rmElmtId) {
125        this.__myState1.purgeDependencyOnElmtId(rmElmtId);
126        this.__myState2.purgeDependencyOnElmtId(rmElmtId);
127        this.__myState3.purgeDependencyOnElmtId(rmElmtId);
128        this.__myState4.purgeDependencyOnElmtId(rmElmtId);
129    }
130    aboutToBeDeleted() {
131        this.__myState1.aboutToBeDeleted();
132        this.__myState2.aboutToBeDeleted();
133        this.__myState3.aboutToBeDeleted();
134        this.__myState4.aboutToBeDeleted();
135        SubscriberManager.Get().delete(this.id__());
136        this.aboutToBeDeletedInternal();
137    }
138    get myState1() {
139        return this.__myState1.get();
140    }
141    set myState1(newValue) {
142        this.__myState1.set(newValue);
143    }
144    get myState2() {
145        return this.__myState2.get();
146    }
147    set myState2(newValue) {
148        this.__myState2.set(newValue);
149    }
150    get myState3() {
151        return this.__myState3.get();
152    }
153    set myState3(newValue) {
154        this.__myState3.set(newValue);
155    }
156    get myState4() {
157        return this.__myState4.get();
158    }
159    set myState4(newValue) {
160        this.__myState4.set(newValue);
161    }
162    initialRender() {
163        this.observeComponentCreation2((elmtId, isInitialRender) => {
164            Column.create();
165        }, Column);
166        {
167            this.observeComponentCreation2((elmtId, isInitialRender) => {
168                if (isInitialRender) {
169                    let paramsLambda = () => {
170                        return {
171                            NamespaceComponent1Link1: this.myState1,
172                            NamespaceComponent1Link2: this.myState2,
173                            NamespaceComponent1Link3: this.myState3,
174                            NamespaceComponent1Link4: this.myState4,
175                            myVar: 100,
176                            myVar2: 80
177                        };
178                    };
179                    ViewPU.create(new AllComponent.NamespaceComponent1(this, {
180                        NamespaceComponent1Link1: this.__myState1,
181                        NamespaceComponent1Link2: this.__myState2,
182                        NamespaceComponent1Link3: this.__myState3,
183                        NamespaceComponent1Link4: this.__myState4,
184                        myVar: 100,
185                        myVar2: 80
186                    }, undefined, elmtId, paramsLambda));
187                }
188                else {
189                    this.updateStateVarsOfChildByElmtId(elmtId, {});
190                }
191            }, null);
192        }
193        this.observeComponentCreation2((elmtId, isInitialRender) => {
194            __Common__.create();
195            __Common__.width(100);
196        }, __Common__);
197        {
198            this.observeComponentCreation2((elmtId, isInitialRender) => {
199                if (isInitialRender) {
200                    let paramsLambda = () => {
201                        return {
202                            NamespaceComponent1Link1: this.myState1,
203                            NamespaceComponent1Link2: this.myState2,
204                            NamespaceComponent1Link3: this.myState3,
205                            NamespaceComponent1Link4: this.myState4,
206                            myVar: 100,
207                            myVar2: 80
208                        };
209                    };
210                    ViewPU.create(new AllComponent.NamespaceComponent1(this, {
211                        NamespaceComponent1Link1: this.__myState1,
212                        NamespaceComponent1Link2: this.__myState2,
213                        NamespaceComponent1Link3: this.__myState3,
214                        NamespaceComponent1Link4: this.__myState4,
215                        myVar: 100,
216                        myVar2: 80
217                    }, undefined, elmtId, paramsLambda));
218                }
219                else {
220                    this.updateStateVarsOfChildByElmtId(elmtId, {});
221                }
222            }, null);
223        }
224        __Common__.pop();
225        {
226            this.observeComponentCreation2((elmtId, isInitialRender) => {
227                if (isInitialRender) {
228                    let paramsLambda = () => {
229                        return {
230                            NamespaceComponent3Link1: this.myState1,
231                            NamespaceComponent3Link2: this.myState2,
232                            NamespaceComponent3Link3: this.myState3,
233                            NamespaceComponent3Link4: this.myState4,
234                            myVar: 100,
235                            myVar2: 80
236                        };
237                    };
238                    ViewPU.create(new AllComponent.default(this, {
239                        NamespaceComponent3Link1: this.__myState1,
240                        NamespaceComponent3Link2: this.__myState2,
241                        NamespaceComponent3Link3: this.__myState3,
242                        NamespaceComponent3Link4: this.__myState4,
243                        myVar: 100,
244                        myVar2: 80
245                    }, undefined, elmtId, paramsLambda));
246                }
247                else {
248                    this.updateStateVarsOfChildByElmtId(elmtId, {});
249                }
250            }, null);
251        }
252        this.observeComponentCreation2((elmtId, isInitialRender) => {
253            __Common__.create();
254            __Common__.height(200);
255        }, __Common__);
256        {
257            this.observeComponentCreation2((elmtId, isInitialRender) => {
258                if (isInitialRender) {
259                    let paramsLambda = () => {
260                        return {
261                            NamespaceComponent3Link1: this.myState1,
262                            NamespaceComponent3Link2: this.myState2,
263                            NamespaceComponent3Link3: this.myState3,
264                            NamespaceComponent3Link4: this.myState4,
265                            myVar: 100,
266                            myVar2: 80
267                        };
268                    };
269                    ViewPU.create(new AllComponent.default(this, {
270                        NamespaceComponent3Link1: this.__myState1,
271                        NamespaceComponent3Link2: this.__myState2,
272                        NamespaceComponent3Link3: this.__myState3,
273                        NamespaceComponent3Link4: this.__myState4,
274                        myVar: 100,
275                        myVar2: 80
276                    }, undefined, elmtId, paramsLambda));
277                }
278                else {
279                    this.updateStateVarsOfChildByElmtId(elmtId, {});
280                }
281            }, null);
282        }
283        __Common__.pop();
284        Column.pop();
285    }
286    rerender() {
287        this.updateDirtyElements();
288    }
289}
290ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent());
291loadDocument(new ImportTest(undefined, {}));
292ViewStackProcessor.StopGetAccessRecording();
293`
294