Skip to content

Commit

Permalink
make sure defaults are non-array object before object.assigning
Browse files Browse the repository at this point in the history
  • Loading branch information
snapwich committed Nov 29, 2017
1 parent 89d8c0e commit 131fc7c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export function newConfig() {
* subscribes to configuration updates. See `subscribe` function for usage.
*/
function getConfig(...args) {
// deep merge config with defaults
let configWithDefaults = Object.assign({}, defaults, config).keys().reduce((memo, key) => {
let c = config[key];
let d = defaults[key];
Expand All @@ -161,8 +162,11 @@ export function newConfig() {
}

if (typeof c !== 'undefined') {
if (typeof c === 'object' && !Array.isArray(c)) {
memo[key] = Object.assign({}, memo[key], c);
if (
typeof d === 'object' && !Array.isArray(d) &&
typeof c === 'object' && !Array.isArray(c)
) {
memo[key] = Object.assign({}, d, c);
} else {
memo[key] = c;
}
Expand Down

0 comments on commit 131fc7c

Please sign in to comment.