Properly merge array config values#128
Merged
shakyShane merged 2 commits intoBrowserSync:masterfrom Apr 9, 2014
probertson:master
Merged
Properly merge array config values#128shakyShane merged 2 commits intoBrowserSync:masterfrom probertson:master
shakyShane merged 2 commits intoBrowserSync:masterfrom
probertson:master
Conversation
Extend _.merge so that Array config values are concatenated instead of replacing default values with user-provided values.
Change the merge mechanism to use _.union instead of Array.concat(), so duplicates between the default config and the user config are only included once.
shakyShane
added a commit
that referenced
this pull request
Apr 9, 2014
Properly merge array config values
Contributor
|
ouch - good catch & thanks! I need to add tests around the config merging, it's getting messy. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
_.mergeworks if an array contains objects (that is, it merges the properties of the objects). However, if the array contains simple values (such as strings in the case of browser-sync config values), it overwrites the values in the default array with values in the user config.For example, suppose I call browser-sync with a config object like this (in my case it's in a gulpfile):
The default config contains these values:
The result of the _merge call in
index.jsis:Note that the user-provided value "ejs" replaces the first value ("js") rather than being added to the array.
This pull request changes the behavior of
_.mergeso that for arrays, the arrays are concatenated. Note that a more robust solution would be needed if there were config parameters that accepted arrays of objects, but as long as the only array config parameters use simple values (string, number, etc.) this approach works.