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

Recursive merging #9

Open
Migushthe2nd opened this issue May 25, 2020 · 1 comment
Open

Recursive merging #9

Migushthe2nd opened this issue May 25, 2020 · 1 comment

Comments

@Migushthe2nd
Copy link

Migushthe2nd commented May 25, 2020

I'm trying to merge the second json (update) with the first (original):

{
    "Files": [
      {
        "FileName": "blyt/PslSelectSinglePlayer.bflyt",
        "Patches": [
          {
            "PaneName": "N_Cnt",
            "Position": {
              "X": 0,
              "Y": -200,
              "Z": 0
            }
          },
          {
            "PaneName": "RootPane",
            "Scale": {
              "X": 0.9,
              "Y": 0.9
            }
          }
        ]
      }
    ]
  }

and update with

{
    "Files": [
      {
        "FileName": "blyt/PslSelectSinglePlayer.bflyt",
        "Patches": [
          {
            "PaneName": "N_Cnt",
            "Position": {
              "X": 0,
              "Y": 0,
              "Z": 0
            }
          }
        ]
      }
    ]
  }

But the result is

{
  "Files": [
    {
      "FileName": "blyt/PslSelectSinglePlayer.bflyt",
      "Patches": [
        {
          "PaneName": "N_Cnt",
          "Position": {
            "X": 0,
            "Y": 0,
            "Z": 0
          }
        }
      ]
    }
  ]
}

while I need it to be

{
  "Files": [
    {
      "FileName": "blyt/PslSelectSinglePlayer.bflyt",
      "Patches": [
        {
          "PaneName": "N_Cnt",
          "Position": {
            "X": 0,
            "Y": 0,
            "Z": 0
          }
        },
        {
          "PaneName": "RootPane",
          "Scale": {
            "X": 0.9,
            "Y": 0.9
          }
        }
      ]
    }
  ]
}

Would it be possible to add an option for this? (Was this behaviour removed in #7 ?)

Edit:
My code:

merge(original, update, [
  'FileName',
  'PaneName'
])
@tnptop
Copy link
Owner

tnptop commented May 26, 2020

To be honest, I didn't take a nested object into account, so as of this comment what the code actually does is just merge the immediate child of the object's properties. Which means this is an oversight in design, not related to #7.

Recursive merging has to be done inside-out, so it'll take a while to properly traverse and ensure the integrity of the object structure. In the worst case there might be a need to re-implement from scratch.

I'll keep you update on the status. Thank you very much for reporting this!

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