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

[Feature request] Pass parent values to customMerge() #263

Open
broofa opened this issue Jan 10, 2024 · 0 comments
Open

[Feature request] Pass parent values to customMerge() #263

broofa opened this issue Jan 10, 2024 · 0 comments

Comments

@broofa
Copy link

broofa commented Jan 10, 2024

Problem: We'd like to require certain merge paths to always be defined.

For example: If attempting to merge objects a and b, and b.properties is defined, we'd like to throw if `a.properties is not defined.

Current solution:
Per this comment, this is accomplished with a customMerge function that looks something like this:

// merge options
customMerge(key) {
  if (key === 'properties') {
    return function (a, b) {
      if (!a) throw Error('properties is not defined');
    }
  }
}

This is awkward. It's just weird that the test for property name and value(s) is split across two different functions.

Proposed solution:
Extend the customMerge() method signature to take key, object_a, object_b. This would allow the code above to be simplified:

// merge options
customMerge(key, a, b) {
  if (key === 'properties' && !a) {
    throw Error('properties is not defined');
  }
}
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

1 participant