Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support parse method result #2485

Merged
merged 8 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
IAssetRef,
IBasicType,
IClassObject,
IClassRealObject,
IComponentRef,
IEntity,
IEntityRef,
IComponentRef,
IHierarchyFile,
IRefEntity
} from "../schema";
Expand Down Expand Up @@ -72,15 +73,34 @@

parseMethod(instance: any, methodName: string, methodParams: Array<IBasicType>) {
return Promise.all(methodParams.map((param) => this.parseBasicType(param))).then((result) => {
return instance[methodName](...result);
const methodCallback = instance[methodName](...result);
const callbackProps = (methodParams?.[0] as IClassRealObject).callbackProps;
if (callbackProps) {
const promises = [];
for (let key in callbackProps) {
const value = callbackProps[key];
const promise = this.parseBasicType(value, methodCallback[key]).then((v) => {
if (methodCallback[key] !== v) {
methodCallback[key] = v;
}
return v;
});
luzhuang marked this conversation as resolved.
Show resolved Hide resolved
promises.push(promise);
}
return Promise.all(promises);
} else {

Check warning on line 91 in packages/loader/src/resource-deserialize/resources/parser/ReflectionParser.ts

View check run for this annotation

Codecov / codecov/patch

packages/loader/src/resource-deserialize/resources/parser/ReflectionParser.ts#L79-L91

Added lines #L79 - L91 were not covered by tests
return methodCallback;
}
zhuxudong marked this conversation as resolved.
Show resolved Hide resolved
});
}

parseBasicType(value: IBasicType, originValue?: any): Promise<any> {
if (Array.isArray(value)) {
return Promise.all(value.map((item) => this.parseBasicType(item)));
} else if (typeof value === "object" && value != null) {
if (ReflectionParser._isClass(value)) {
if (ReflectionParser._isRealClass(value)) {
return Promise.resolve(Loader.getClass(value["classReal"]));

Check warning on line 102 in packages/loader/src/resource-deserialize/resources/parser/ReflectionParser.ts

View check run for this annotation

Codecov / codecov/patch

packages/loader/src/resource-deserialize/resources/parser/ReflectionParser.ts#L102

Added line #L102 was not covered by tests
} else if (ReflectionParser._isClass(value)) {
// class object
return this.parseClassObject(value);
} else if (ReflectionParser._isAssetRef(value)) {
Expand Down Expand Up @@ -158,6 +178,10 @@
return value["class"] !== undefined;
}

private static _isRealClass(value: any): value is IClassObject {
return value["classReal"] !== undefined;
}

private static _isAssetRef(value: any): value is IAssetRef {
return value["refId"] !== undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ export type IClassObject = {
props?: { [key: string]: IBasicType | IMethodParams };
};

export type IClassRealObject = {
classReal: string;
callbackProps?: { [key: string]: IBasicType | IMethodParams };
};

export type IBasicType =
| string
| number
Expand All @@ -86,6 +91,7 @@ export type IBasicType =
| undefined
| IAssetRef
| IClassObject
| IClassRealObject
| IMethodParams
| IEntityRef;

Expand Down
Loading