Skip to content

Conversation

djeglin
Copy link
Contributor

@djeglin djeglin commented Nov 22, 2016

Relates to static-dev/spike#38

Referenced PR exposed issue that nested options objects being passed from the API are not merged properly with options from App.js – Because Object.assign copies the full reference over if the value of a key:value pair is an object. This was leading to server options set in App.js being ignored.

This PR fixes this issue by changing the way options are merged to use a method suitable for nested objects.

There is a new test to check that the merge is operating properly.

Copy link
Member

@jescalan jescalan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to run this! Just thinking we might want to outsource the deep merge...

lib/config.js Outdated
}

return finalObject
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So something like _.merge might be a better approach here...

Copy link
Contributor Author

@djeglin djeglin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the custom functions and instead used _.merge to merge the objects.

lib/config.js Outdated
// merges API options into app.js options
let allOpts = Object.assign(this.parseAppJs(opts), opts)
let appJsOpts = this.parseAppJs(opts)
let allOpts = merge(appJsOpts, opts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to separate out appJsOpts to a variable here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was when I was using the custom functions as it was a little easier to understand (and didn't mess about between contexts so much), but it may be better now to revert this line to have this.parseAppJs(opts) inline.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok let's swap that back, then looks good to merge!

@jescalan
Copy link
Member

🎉

@jescalan jescalan merged commit 4440d5d into static-dev:master Nov 22, 2016
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

Successfully merging this pull request may close these issues.

2 participants