-
-
Notifications
You must be signed in to change notification settings - Fork 290
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
fix(core): add support for built-in types in deepCopy
#2691
fix(core): add support for built-in types in deepCopy
#2691
Conversation
WalkthroughThe Changes
Assessment against linked issues
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (2)
Additional comments not posted (5)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Actionable comments posted: 0
Out of diff range and nitpick comments (1)
packages/core/src/utils/objects/deepClone.ts (1)
Line range hint
16-85
: RefactordeepClone
to improve readability and maintainability.- export const deepClone = (source: any, stack = new WeakMap()): any => { + export const deepClone = (source: any, stack = new WeakMap<any, any>()): any => { // provides an early exit for simple cases if (isBasicType(source)) { return source; } const stacked = stack.get(source); if (stacked) { // See issue #1619 return stacked; } if (ArrayBuffer.isView(source)) { return Buffer.isBuffer(source) ? Buffer.from(source) : // adds support for all kind of TypedArray such as Int8Array, Uint8Array, etc new (classOf(source))(source.buffer.slice(0), source.byteOffset, source.byteLength); } if (isDate(source)) { return new Date(source); } if (isRegExp(source)) { return new RegExp(source); } if (Array.isArray(source)) { const clone: unknown[] = []; stack.set(source, clone); source.forEach((item, idx) => (clone[idx] = deepClone(item, stack))); return clone; } if (source instanceof Map) { const clone = new Map(); stack.set(source, clone); source.forEach((value, key) => clone.set(deepClone(key, stack), deepClone(value, stack))); return clone; } if (source instanceof Set) { const clone = new Set(); stack.set(source, clone); source.forEach((value) => clone.add(deepClone(value, stack))); return clone; } const clone = Object.create(Reflect.getPrototypeOf(source)); stack.set(source, clone); Reflect.ownKeys(source).forEach((key) => { // respects property descriptors and the prototype chain more explicitly, which is important for objects with getter/setter. const descriptor = Object.getOwnPropertyDescriptor(source, key); if (descriptor) { if (!isFunction(descriptor.value)) { Object.defineProperty(clone, key, { ...descriptor, value: deepClone(descriptor.value, stack) }); } else { Object.defineProperty(clone, key, descriptor); } } }); return clone; };Suggest breaking down the function into smaller, more manageable functions, each handling a specific type of data structure. This will improve readability and maintainability.
@derevnjuk perfect ;) |
🎉 This PR is included in version 7.68.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Information
Todos
closes #2690
Summary by CodeRabbit
deepClone
function for more efficient handling of various data types including maps, sets, arrays, and buffer types.Base
andTest
classes to enhance functionality.