Merge extend
objects deeply by default
#2679
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description by @adamwathan
This PR changes how the
extend
behavior undertheme
works by default, and merges extensions deeply/recursively instead of shallowly.Here's a simple example — given this input:
...historically, you'd get this output:
All of the
red
values would be gone, only450
would exist because the newred
object replaced the entire oldred
object.After this PR, you'd get this output:
...where
450
is merged with the existing object.This is a breaking change because some people might be depending on this behavior, especially third-party plugins that might have been authored with this behavior in mind when designing their own customization API.
This is one of the most common problems people run into when trying to do stuff like this in their config file though, so we think it's worth it to correct this default.
If someone did want to replace the entire color
red
after this PR is merged, they could still do so using one of two ways:1. Replace all of the same sub-values
If your new color uses the same
50
–900
scale as the built-in color, then things will just work:2. Replace the color without using
extend
If you want to use a different naming scheme, don't use
extend
at all when overriding the values:This will override all of the colors so you will have to redefine each one you need, but you can do that like so:
If you are renaming everything like this though you are likely already replacing all of the colors so this won't even be an issue.
Colors are the only place where this is applicable in the default theme (arrays like in
fontFamily
are not deep merged), so we don't expect this will really have a big impact. If anything, I expect most people are already working around this by doing stuff like this:...so they'll actually be able to just delete some of that workaround code that is no longer necessary.