Skip to content
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

Option to not replace duplicated objects/arrays/values with "_duplicate_["lorem"]" unless is in a circular dependency #52

Open
robertdumitrescu opened this issue Nov 12, 2020 · 4 comments

Comments

@robertdumitrescu
Copy link

Well, exactly like my title says, it would be nice to have an option to not replace duplicated objects/arrays and so on unless a circular dependency is detected.

@shilman
Copy link
Member

shilman commented Nov 12, 2020

Need more context. Do you have a repro repo you can share?

@robertdumitrescu
Copy link
Author

Hey, thanks for getting so quickly back to me.

So I have this config object:

{
    "layout": "pass",
    "level": {
            "weight": 40000,
            "color": "red"
        },
    "minLevelWeight": 40000,
    "levelsDefinitions": {
        "error": {
            "weight": 40000,
            "color": "red"
        },
        "fatal": {
            "weight": 50000,
            "color": "magenta"
        },
        "off": {
            "weight": 1.7976931348623157e+308,
            "color": "grey"
        }
    },
    "logs": [],
    "levelsCollector": {
        "error": [],
        "fatal": [],
        "off": []
    },
    "tagsCollector": {},
    "trackingIdsCollector": {},
    "trackingIds": [],
    "getLocation": true
}

If you put that through

Telejson.stringify(object, {space: 4})

You end up with:

{
    "layout": "pass",
    "level": {
        "weight": 40000,
        "color": "red"
    },
    "minLevelWeight": 40000,
    "levelsDefinitions": {
        "error": "_duplicate_[\"level\"]",
        "fatal": {
            "weight": 50000,
            "color": "magenta"
        },
        "off": {
            "weight": 1.7976931348623157e+308,
            "color": "grey"
        }
    },
    "logs": [],
    "levelsCollector": {
        "error": [],
        "fatal": [],
        "off": []
    },
    "tagsCollector": {},
    "trackingIdsCollector": {},
    "trackingIds": [],
    "getLocation": true
}

Notice the _duplicate_[\"level\"] and that is being replaced in a non-circular dependency context. So, it would be nice to have an option to not replace it with the string, unless is a circular dependency context. That way can be used very easily in unit/integration tests fixtures/assertions.

@robertdumitrescu
Copy link
Author

Any update on this?

@robertdumitrescu
Copy link
Author

Can we at least have a configuration level for this? Basically consider it circular if it repeats more than X times within the same circular path?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants