From 99965c9162c3af62651aa56733819a93db85a5a7 Mon Sep 17 00:00:00 2001 From: PP Date: Sun, 8 Oct 2023 10:18:12 +0800 Subject: [PATCH] deprecate `misc.isPlainEmptyObj_DEV`, use `js.isEmptyObject` instead (#16341) * fix: deprecate `isPlainEmptyObj_DEV` --- cocos/base/utils/src/internal-index.ts | 9 +++++++++ cocos/core/data/utils/attribute.ts | 4 ++-- cocos/core/utils/misc.ts | 9 ++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cocos/base/utils/src/internal-index.ts b/cocos/base/utils/src/internal-index.ts index 5507c072a09..eb4c2aee164 100644 --- a/cocos/base/utils/src/internal-index.ts +++ b/cocos/base/utils/src/internal-index.ts @@ -1 +1,10 @@ +import { js } from './js'; + export { ScalableContainer, scalableContainerManager } from './memop/scalable-container'; + +export function isPlainEmptyObj (obj): boolean { + if (!obj || obj.constructor !== Object) { + return false; + } + return js.isEmptyObject(obj); +} diff --git a/cocos/core/data/utils/attribute.ts b/cocos/core/data/utils/attribute.ts index 05a9a8ecfbc..eeeeb3dde08 100644 --- a/cocos/core/data/utils/attribute.ts +++ b/cocos/core/data/utils/attribute.ts @@ -27,7 +27,7 @@ import { EDITOR } from 'internal:constants'; import { log, warnID } from '@base/debug'; import { cclegacy } from '@base/global'; import { js } from '@base/utils'; -import { isPlainEmptyObj_DEV } from '../../utils/misc'; +import { isPlainEmptyObj } from '@base/utils/internal'; const { formatStr, get, getClassName, isChildClassOf, value } = js; @@ -228,7 +228,7 @@ export function getTypeChecker_ET (type: string, attributeName: string) { if (typeof defaultVal === 'undefined') { return; } - const isContainer = Array.isArray(defaultVal) || isPlainEmptyObj_DEV(defaultVal); + const isContainer = Array.isArray(defaultVal) || isPlainEmptyObj(defaultVal); if (isContainer) { return; } diff --git a/cocos/core/utils/misc.ts b/cocos/core/utils/misc.ts index 158958a9adc..0fc307f6466 100644 --- a/cocos/core/utils/misc.ts +++ b/cocos/core/utils/misc.ts @@ -30,6 +30,7 @@ import { setTimeoutRAF } from '@pal/utils'; import { cclegacy } from '@base/global'; import { warnID } from '@base/debug'; import { js } from '@base/utils'; +import { isPlainEmptyObj } from '@base/utils/internal'; import { macro } from '../platform/macro'; const { getClassName, getset, isEmptyObject } = js; @@ -205,12 +206,14 @@ export function tryCatchFunctor_EDITOR (funcName: string): (comp: unknown) => vo * @param obj @en The object to check. @zh 要检查的对象。 * @returns @en True if it is an empty object. False if it is not an empty object, not Object type, null or undefined. * @ 如果是空对象,返回 true。如果不是空对象,不是Object类型,空或未定义,则为假。 + * + * @deprecated `misc.isPlainEmptyObj_DEV` is deprecated since v3.9.0, please use `js.isEmptyObject` instead. */ export function isPlainEmptyObj_DEV (obj): boolean { - if (!obj || obj.constructor !== Object) { - return false; + if (DEBUG) { + warnID(16001, 'misc.isPlainEmptyObj_DEV', '3.9.0', 'js.isEmptyObject'); } - return isEmptyObject(obj); + return isPlainEmptyObj(obj); } /**