Files
cocos4/cocos/core/utils/js.ts
T
Jare Guo a0a992de5d remove asserts from addChild & sync 2D changes (#7479)
* remove asserts from addChild

* expose js._registeredClassIds & js._registeredClassNames (sync #3174)

To unload scripts dynamically.
Also revert part of changes from https://github.com/cocos-creator/engine/pull/3204/files#diff-cabe5229c3c6e31339220008e54fe853L421

* remove unused code (sync #3174)

* minor tweak (sync #3421)

* should not invoke component if destroy() called before node activating (sync #3430)

* node should removed and destroyed with scene (sync #3456 #3483)

* fix WebGL detection on Android browsers (sync #3510)

* remove redundant right shift for bitwise operation (sync #3754)

* fix label blur when using dark font color (sync #3949)

* refine tooltip of Block Input Event (sync #4053)

* fix IE/Edge exception when output log/warn before engine initialization(sync #4447, #4500)

* sync class, attribute (#4689, #4712, #4781, #4712)

* fix loading unknown texture format (sync #4820)

* prefer toLowerCase to toLocaleLowerCase + sync #5114

* optimize bezier calculation (sync #5155)

* fix potential memory leak in scene-editor (sync #5643)

* fix _posDirty error of Mask on native platform (sync #6168)
2020-10-15 17:28:14 +08:00

154 lines
4.2 KiB
TypeScript

/*
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2011-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import * as jsarray from './array';
import IDGenerator from './id-generator';
import {
_idToClass,
_nameToClass,
_getClassById,
_getClassId,
_setClassId,
addon,
clear,
createMap,
extend,
formatStr,
get,
getClassByName,
getClassName,
getPropertyDescriptor,
getset,
getSuper,
isChildClassOf,
isNumber,
isString,
mixin,
obsolete,
obsoletes,
set,
setClassName,
setClassAlias,
shiftArguments,
unregisterClass,
value,
} from './js-typed';
import Pool from './pool';
import { legacyCC } from '../global-exports';
export * from './js-typed';
export {default as IDGenerator} from './id-generator';
export {default as Pool} from './pool';
export const array = jsarray;
export const js = {
IDGenerator,
Pool,
array: jsarray,
isNumber,
isString,
getPropertyDescriptor,
addon,
mixin,
extend,
getSuper,
isChildClassOf,
clear,
value,
getset,
get,
set,
unregisterClass,
getClassName,
setClassName,
setClassAlias,
getClassByName,
/**
* @en All classes registered in the engine, indexed by name.
* @zh 引擎中已注册的所有类型,通过名称进行索引。
* @private
* @example
* ```
* import { js } from 'cc';
* // save all registered classes before loading scripts
* let builtinClassIds = js._registeredClassIds;
* let builtinClassNames = js._registeredClassNames;
* // load some scripts that contain CCClass
* ...
* // clear all loaded classes
* js._registeredClassIds = builtinClassIds;
* js._registeredClassNames = builtinClassNames;
* ```
*/
get _registeredClassNames (): typeof _nameToClass {
return Object.assign({}, _nameToClass);
},
set _registeredClassNames (value: typeof _nameToClass) {
clear(_nameToClass);
Object.assign(_nameToClass, value);
},
/**
* @en All classes registered in the engine, indexed by ID.
* @zh 引擎中已注册的所有类型,通过 ID 进行索引。
* @private
* @example
* ```
* import { js } from 'cc';
* // save all registered classes before loading scripts
* let builtinClassIds = js._registeredClassIds;
* let builtinClassNames = js._registeredClassNames;
* // load some scripts that contain CCClass
* ...
* // clear all loaded classes
* js._registeredClassIds = builtinClassIds;
* js._registeredClassNames = builtinClassNames;
* ```
*/
get _registeredClassIds (): typeof _idToClass {
return Object.assign({}, _idToClass);
},
set _registeredClassIds (value: typeof _idToClass) {
clear(_idToClass);
Object.assign(_idToClass, value);
},
_getClassId,
_setClassId,
_getClassById,
obsolete,
obsoletes,
formatStr,
shiftArguments,
createMap,
};
/**
* This module provides some JavaScript utilities.
* All members can be accessed with "cc.js".
*/
legacyCC.js = js;