Repeat support listitem

Signed-off-by: houhaoyu <houhaoyu@huawei.com>
Change-Id: I437c3b43be15e10f092818f14eb754c33349b0a3
This commit is contained in:
houhaoyu 2024-05-14 21:04:50 +08:00
parent 459e02a8c0
commit dac18cc833
2 changed files with 91 additions and 1 deletions

View File

@ -3210,7 +3210,7 @@ function isLazyForEachChild(node: ts.ExpressionStatement): boolean {
while (temp && !ts.isEtsComponentExpression(temp) && !ts.isCallExpression(temp)) {
temp = temp.parent;
}
if (temp && temp.expression && (temp.expression as ts.Identifier).escapedText.toString() === COMPONENT_LAZYFOREACH) {
if (temp && temp.expression && (temp.expression as ts.Identifier).escapedText?.toString() === COMPONENT_LAZYFOREACH) {
return true;
}
return false;

View File

@ -57,6 +57,23 @@ struct ChildComponent {
.height(500)
}
}
@Component
struct ChildComponent2 {
@State arr: ClassA[] = [new ClassA('0'), new ClassA('1'), new ClassA('2')]
count: number = 0;
build() {
List() {
Repeat<ClassA>(this.arr)
.each((obj: RepeatItem<ClassA>) => {
ListItem() {
Text(obj.item.message)
}
})
}
.height(500)
}
}
`
exports.expectResult =
`"use strict";
@ -189,6 +206,79 @@ class ChildComponent extends ViewPU {
this.updateDirtyElements();
}
}
class ChildComponent2 extends ViewPU {
constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) {
super(parent, __localStorage, elmtId, extraInfo);
if (typeof paramsLambda === "function") {
this.paramsGenerator_ = paramsLambda;
}
this.__arr = new ObservedPropertyObjectPU([new ClassA('0'), new ClassA('1'), new ClassA('2')], this, "arr");
this.count = 0;
this.setInitiallyProvidedValue(params);
this.finalizeConstruction();
}
setInitiallyProvidedValue(params) {
if (params.arr !== undefined) {
this.arr = params.arr;
}
if (params.count !== undefined) {
this.count = params.count;
}
}
updateStateVars(params) {
}
purgeVariableDependenciesOnElmtId(rmElmtId) {
this.__arr.purgeDependencyOnElmtId(rmElmtId);
}
aboutToBeDeleted() {
this.__arr.aboutToBeDeleted();
SubscriberManager.Get().delete(this.id__());
this.aboutToBeDeletedInternal();
}
get arr() {
return this.__arr.get();
}
set arr(newValue) {
this.__arr.set(newValue);
}
initialRender() {
this.observeComponentCreation2((elmtId, isInitialRender) => {
List.create();
List.height(500);
}, List);
this.observeComponentCreation2((elmtId, isInitialRender) => {
Repeat(this.arr, this).each((obj) => {
{
const itemCreation = (elmtId, isInitialRender) => {
ViewStackProcessor.StartGetAccessRecordingFor(elmtId);
itemCreation2(elmtId, isInitialRender);
if (!isInitialRender) {
ListItem.pop();
}
ViewStackProcessor.StopGetAccessRecording();
};
const itemCreation2 = (elmtId, isInitialRender) => {
ListItem.create(deepRenderFunction, true);
};
const deepRenderFunction = (elmtId, isInitialRender) => {
itemCreation(elmtId, isInitialRender);
this.observeComponentCreation2((elmtId, isInitialRender) => {
Text.create(obj.item.message);
}, Text);
Text.pop();
ListItem.pop();
};
this.observeComponentCreation2(itemCreation2, ListItem);
ListItem.pop();
}
}).render(isInitialRender);
}, Repeat);
List.pop();
}
rerender() {
this.updateDirtyElements();
}
}
ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent());
loadDocument(new HomeComponent(undefined, {}));
ViewStackProcessor.StopGetAccessRecording();