-
Notifications
You must be signed in to change notification settings - Fork 16
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
Feature request: named circular references #43
Comments
The algorithm works a bit different than in
The current algorithm is mainly tuned for performance and adding named references would have another tracking overhead. It requires another array to keep the names. I did not check how bad the overhead would be, but that has to be checked first. |
@BridgeAR thanks for the response. Your idea with path as strong in circular reference is even better! One of the main benefits as I see it: we will not lose data about circular references and it will be serializable/deserializable. About performance: that is why I suggest to add such functionality via flag in configure. So that by default it will be turned off and thus will not impact main performance metrics I guess? |
Btw, I would imagine it to work something like that: const circular = {
a: 1,
outer: {
prop: {}
}
}
circular.outer.prop.circular = circular.outer
console.log(stringify(circular))
{
"a": 1,
"outer": {
"prop": {
"circular": "[Circular: &.outer]"
}
}
} On my opinion easier to understand(& is like reference to original object) |
I have a reference implementation but it does slow down the overall serialization. |
I'm not an expert in performance but doesn't such approach work? if (flagName) {
// do something
} else {
// do something else
} use const actionsConfig = {
featureName: () => {
// do something
},
withoutFeatureName: () => {
// do something else
},
}
const flagName = 'featureName'
actionsConfig[flagName](); The point is that second approach should be O(1) complexity. |
When using
util.inspect(myObject))
circular references are named likeref 1
,ref 2
etc...Would be great to have an option for named circular references, something like this:
The text was updated successfully, but these errors were encountered: