-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 Tree copy by doing a shallow copy of the value #5081
Fix Tree copy by doing a shallow copy of the value #5081
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Hmm I am not sure about doing just a shallow copy. I see your issue with the circular reference but aren't you better off modifying your model object being used in the treenode than to make this assumption of 1 level deep? |
I could write a deep clone that leaves the |
OK yeah i would do a deep copy without the |
something like this.. function deepCopyWithoutData(obj) {
if (obj === null || typeof obj !== 'object') {
return obj;
}
if (Array.isArray(obj)) {
return obj.map(item => deepCopyWithoutData(item));
}
const result = {};
for (let key in obj) {
if (key !== 'data') {
result[key] = deepCopyWithoutData(obj[key]);
}
}
return result;
} |
Thanks, I made a sort of similar implementation that handles some edge-cases. JavaScript is messy 😅 |
@melloware Is this PR good to merge like this? I've tested it both in the docs and my own project and it works on both |
503c0b5
to
e32a525
Compare
Fixes #5080
This does a shallow clone of the value, instead of a deep clone. This way data is not modified. The copy is only 1 level deep. In testing, this worked fine. But someone with more knowledge of the code should review and decide if a deeper copy (excluding data) is needed.