-
-
Notifications
You must be signed in to change notification settings - Fork 305
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
recursion in deepEqual() on object graphs with cycles #434
Comments
Ugh, tested with |
Tested with Let me know if you'd accept a PR to switch to that? |
One thing you can do, is call a custom stringify on both objects, and then compare them after calling JSON parse on them. const obj1 = {}; // has circular references
const obj2 = {}; // has circular references
const parsed1 = JSON.parse(customStringify(obj1));
const parsed2 = JSON.parse(customStringify(obj2)); // then compare the two parsed objects, with a deep equals routine Using a custom stringify function like this, which ignores circular references: export const customStringify = function (v: any) {
const cache = new Map();
return JSON.stringify(v, function (key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.get(value)) {
// Circular reference found, discard key
return;
}
// Store value in our collection
cache.set(value, true);
}
return value;
});
}; |
My work-around for now is just to import A work-around won't provide good feedback though, for example I could just overwrite |
For starters, I wanted to see if The |
I'm really not a fan of switching which dep we're using here. I think the appropriate path is continuing to pursue the relevant change in |
@ljharb why? |
@ljharb I wasn't trying to be short with you, if I came off that way :-) I am genuinely asking, why wouldn't you switch to a more current/maintained package? From my perspective, What's better or more appropriate about enhancing |
why not both? use both libs? / make both libs available/exposed |
@ORESoftware how? (and why?) |
@mindplay-dk mainly because there could be any number of edge cases the tests (unfortunately) don't cover, so it could break people, and because the original author of I'd like to see a PR open on deep-equal, which could be reviewed, and then let's see if we can get it merged and released - before trying to make a potentially risky change in tape. |
I now maintain Follow inspect-js/node-deep-equal#19 for an underlying fix to support circular references. |
- See nodejs/node@d3aafd0 - Fixes #19 - Will allow tape-testing/tape#434 to be fixed
v2 of deep-equal will resolve this, which will be included in v5 of tape. |
deep-equal is upgraded in 898a6e7; closing. Once v5 is out, this will be resolved. |
I have an object graph with cycles, and I'm testing with
tape
, and it keeps on throwingRangeError: Maximum call stack size exceeded
.I traced it back to this issue in
deep-equal
.It was reported march'15, and it doesn't look like
deep-equal
has received much maintenance, so maybe it's time to consider switching to eitherfast-deep-equal
ordeep-eql
, both of which seem to be more popular and more recently active?Although I didn't see a test-case with circular references in any of those two projects' tests either.
If you let me know how you'd like to address this issue, I can try to help?
The text was updated successfully, but these errors were encountered: