Signed-off-by: laibo102 <laibo2@huawei.com>
Change-Id: Ifb1e35c63849e7442819d7cfacd3171a9d9c1a96
This commit is contained in:
laibo102
2022-05-31 18:34:24 +08:00
parent 7e5dee5d9b
commit 9398437e24
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
exports.source = `
@Component
struct TitleComp {
@Link title: string
build() {
Text(this.title)
}
}
@Entry
@Component
struct TestPage{
@State value: string = 'hello world'
@Builder
TitleCompView() {
TitleComp({title: $value})
}
build() {
Flex() {
this.TitleCompView()
}
}
}
`
exports.expectResult =
`class TitleComp extends View {
constructor(compilerAssignedUniqueChildId, parent, params) {
super(compilerAssignedUniqueChildId, parent);
this.__title = new SynchedPropertySimpleTwoWay(params.title, this, "title");
this.updateWithValueParams(params);
}
updateWithValueParams(params) {
}
aboutToBeDeleted() {
this.__title.aboutToBeDeleted();
SubscriberManager.Get().delete(this.id());
}
get title() {
return this.__title.get();
}
set title(newValue) {
this.__title.set(newValue);
}
render() {
Text.create(this.title);
Text.pop();
}
}
class TestPage extends View {
constructor(compilerAssignedUniqueChildId, parent, params) {
super(compilerAssignedUniqueChildId, parent);
this.__value = new ObservedPropertySimple('hello world', this, "value");
this.updateWithValueParams(params);
}
updateWithValueParams(params) {
if (params.value !== undefined) {
this.value = params.value;
}
}
aboutToBeDeleted() {
this.__value.aboutToBeDeleted();
SubscriberManager.Get().delete(this.id());
}
get value() {
return this.__value.get();
}
set value(newValue) {
this.__value.set(newValue);
}
TitleCompView() {
let earlierCreatedChild_2 = this.findChildById("2");
if (earlierCreatedChild_2 == undefined) {
View.create(new TitleComp("2", this, { title: this.__value }));
}
else {
earlierCreatedChild_2.updateWithValueParams({});
View.create(earlierCreatedChild_2);
}
}
render() {
Flex.create();
this.TitleCompView();
Flex.pop();
}
}
loadDocument(new TestPage("1", undefined, {}));
`