Update: GridItem transform and its UT

Signed-off-by: laibo102 <laibo2@huawei.com>
Change-Id: I9c036706b2465af4383854a5286a0d19251dbc6e
This commit is contained in:
laibo102
2022-08-11 19:40:15 +08:00
parent f4f4a8f920
commit 577a45e710
4 changed files with 58 additions and 22 deletions
+3
View File
@@ -313,3 +313,6 @@ export const FOREACHUPDATEFUNCTION: string = 'forEachUpdateFunction';
export const ALLOCATENEWELMETIDFORNEXTCOMPONENT: string = 'AllocateNewElmetIdForNextComponent';
export const STATE_OBJECTLINK_DECORATORS: string[] = [COMPONENT_STATE_DECORATOR, COMPONENT_OBJECT_LINK_DECORATOR];
export const COMPONENT_INITIAl_RENDER_FUNCTION: string = 'initialRender';
export const GRID_COMPONENT: string = 'Grid';
export const GRIDITEM_COMPONENT: string = 'GridItem';
export const WILLUSEPROXY: string = 'willUseProxy';
+39 -17
View File
@@ -80,7 +80,10 @@ import {
FOREACHITEMIDFUNC,
__LAZYFOREACHITEMIDFUNC,
FOREACHUPDATEFUNCTION,
COMPONENT_INITIAl_RENDER_FUNCTION
COMPONENT_INITIAl_RENDER_FUNCTION,
GRIDITEM_COMPONENT,
GRID_COMPONENT,
WILLUSEPROXY
} from './pre_define';
import {
INNER_COMPONENT_NAMES,
@@ -582,23 +585,9 @@ function createItemBlock(
itemRenderInnerStatements: ts.Statement[],
deepItemRenderInnerStatements: ts.Statement[]
): ts.Block {
const etsComponent: ts.EtsComponentExpression = getEtsComponentExpression(node);
let isLazyCreate: ts.BooleanLiteral = ts.factory.createTrue();
if (etsComponent && etsComponent.arguments[0]) {
if (etsComponent.arguments[0] as ts.StringLiteral.text === 'false') {
isLazyCreate = ts.factory.createFalse();
}
}
return ts.factory.createBlock(
[
ts.factory.createVariableStatement(
undefined,
ts.factory.createVariableDeclarationList(
[ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE),
undefined, undefined, isLazyCreate)],
ts.NodeFlags.Const
)
),
createIsLazyCreate(node),
createItemCreation(node, itemRenderInnerStatements),
createObservedShallowRender(node, itemRenderInnerStatements),
createObservedDeepRender(node, deepItemRenderInnerStatements),
@@ -617,6 +606,39 @@ function createItemBlock(
);
}
function createIsLazyCreate(node: ts.ExpressionStatement): ts.VariableStatement {
const etsComponent: ts.EtsComponentExpression = getEtsComponentExpression(node);
if (etsComponent) {
if ((etsComponent.expression as ts.Identifier).escapedText.toString() === GRIDITEM_COMPONENT) {
if (etsComponent.arguments[0] && (etsComponent.arguments[0] as ts.StringLiteral).text === 'false') {
return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList(
[ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE),
undefined, undefined, ts.factory.createFalse())], ts.NodeFlags.Const));
} else {
return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList(
[ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE), undefined, undefined,
ts.factory.createBinaryExpression(
ts.factory.createTrue(), ts.factory.createToken(ts.SyntaxKind.AmpersandAmpersandToken),
ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(
ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier(GRID_COMPONENT), ts.factory.createIdentifier(WILLUSEPROXY)
), undefined, []), ts.factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken),
ts.factory.createTrue()))))], ts.NodeFlags.Const));
}
} else {
if (etsComponent.arguments[0] && (etsComponent.arguments[0] as ts.StringLiteral).text === 'false') {
return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList(
[ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE),
undefined, undefined, ts.factory.createFalse())], ts.NodeFlags.Const));
} else {
return ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList(
[ts.factory.createVariableDeclaration(ts.factory.createIdentifier(ISLAZYCREATE),
undefined, undefined, ts.factory.createTrue())], ts.NodeFlags.Const));
}
}
}
}
function createItemCreation(
node: ts.ExpressionStatement,
itemRenderInnerStatements: ts.Statement[]
@@ -823,7 +845,7 @@ function processForEachComponent(node: ts.ExpressionStatement, newStatements: ts
ts.factory.createIdentifier(FOREACH_GET_RAW_OBJECT)), undefined, [argumentsArray[0]]);
}
argumentsArray.splice(0, 1, arrayObserveredObject);
const newArrowNode: ts.ArrowFunction =
const newArrowNode: ts.ArrowFunction =
processForEachBlock(node.expression, log, isInnerBuilder) as ts.ArrowFunction;
if (newArrowNode) {
argumentsArray.splice(1, 1, newArrowNode);
@@ -18,9 +18,11 @@ exports.source = `
@Component
struct ParentView {
build() {
GridItem('true') {
Text('xx').width(100)
}.width(200).height(100)
Grid() {
GridItem('true') {
Text('xx').width(100)
}.width(200).height(100)
}
}
}
`
@@ -45,8 +47,16 @@ exports.expectResult =
this.aboutToBeDeletedInternal();
}
initialRender() {
this.observeComponentCreation((elmtId, isInitialRender) => {
ViewStackProcessor.StartGetAccessRecordingFor(elmtId);
Grid.create();
if (!isInitialRender) {
Grid.pop();
}
ViewStackProcessor.StopGetAccessRecording();
});
{
const isLazyCreate = true;
const isLazyCreate = true && (Grid.willUseProxy() === true);
const itemCreation = (elmtId, isInitialRender) => {
ViewStackProcessor.StartGetAccessRecordingFor(elmtId);
GridItem.create(deepRenderFunction, isLazyCreate);
@@ -104,6 +114,7 @@ exports.expectResult =
observedDeepRender();
}
}
Grid.pop();
}
rerender() {
this.updateDirtyElements();
@@ -208,7 +208,7 @@ class Test extends View {
const __lazyForEachItemGenFunction = _item => {
const row = _item;
{
const isLazyCreate = true;
const isLazyCreate = true && (Grid.willUseProxy() === true);
const itemCreation = (elmtId, isInitialRender) => {
ViewStackProcessor.StartGetAccessRecordingFor(elmtId);
GridItem.create(deepRenderFunction, isLazyCreate);