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