-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[DON'T MERGE] Add _decorator.ccclass.forward()
helper decorator to allow transfer cc-class information
#14961
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,6 +229,30 @@ export function createMap (forceDictMode?: boolean): any { | |
return map; | ||
} | ||
|
||
/** | ||
* @internal | ||
* @engineInternal | ||
*/ | ||
export function transferCCClassIdAndName ( | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
originalConstructor: Function, | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
newConstructor: Function, | ||
) { | ||
const className = (originalConstructor.prototype as unknown as { [classNameTag]: string | undefined })[classNameTag]; | ||
const classId = getClassId(originalConstructor, false); | ||
|
||
unregisterClass(originalConstructor); | ||
|
||
if (className) { | ||
doSetClassName(className, newConstructor as Constructor<any>); | ||
} | ||
if (classId) { | ||
_setClassId(classId, newConstructor as Constructor<any>); | ||
} | ||
} | ||
|
||
/** | ||
* @en | ||
* Gets class name of the object, if object is just a {} (and which class named 'Object'), it will return "". | ||
|
@@ -719,10 +743,12 @@ export function unregisterClass (...constructors: Function[]) { | |
const p = constructor.prototype; | ||
const classId = p[classIdTag]; | ||
if (classId) { | ||
delete p[classIdTag]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we have a registerClass method, then it should satisfy the following: So I don't think it's very necessary to reset a class's own properties. Literally speaking, unregistering a class doesn't necessarily have to include resetting or clearing the target class. When a class needs to be unregistered, it's often no longer needed, so its own data can be safely garbage collected without the need for a reset. |
||
delete _idToClass[classId]; | ||
} | ||
const classname = p[classNameTag]; | ||
if (classname) { | ||
delete p[classNameTag]; | ||
delete _nameToClass[classname]; | ||
} | ||
const aliases = p[aliasesTag]; | ||
|
@@ -732,6 +758,7 @@ export function unregisterClass (...constructors: Function[]) { | |
delete _nameToClass[alias]; | ||
delete _idToClass[alias]; | ||
} | ||
delete p[aliasesTag]; | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now, use engineInternal instead