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

Fix case where multiple sections with same settings could modify shared configuration #48

Merged
merged 2 commits into from
May 13, 2016

Conversation

mridgway
Copy link
Contributor

See the test fixture where previously "settings": ["lang:es"] would modify the shared object with foo: 3 causing ycb.read({ lang: 'fr' }) to also resolve to 3 even though it should be 1.

@lingyan

@drewfish
Copy link
Contributor

drewfish commented May 12, 2016

Nice test case.

I'm wondering if the mergeDeep(cloneDeep()) could be optimized some how. Perhaps a special version of mergeDeep() where instead of just copy from to (ack) it does a deepClone() of to.
https://github.com/yahoo/ycb/blob/master/lib/mergeDeep.js#L12

edit: Or maybe this is where the cloneDeep() could be introduced:
https://github.com/yahoo/ycb/blob/master/lib/mergeDeep.js#L21

@mridgway
Copy link
Contributor Author

I agree this might be heavy handed, but it is only run at instantiation time as well. Interestingly this was the last place that assumed that mergeDeep mutated to rather than returning a new object, so I will look into that. I will need to make sure that it doesn't affect the performance of the settings merge during read.

In a related note: in a previous PR I optimized mergeDeep to clone from inline rather than do the cloneDeep on the full object up front. It would be a similar performance gain, but only during YCB instantiation.

@lingyan
Copy link
Member

lingyan commented May 12, 2016

Changing something that might affect read sounds a little scary. I'm ok with mergeDeep(cloneDeep) if it is only a one-time cost at instantiation.

@redonkulus
Copy link
Collaborator

👍

@mridgway
Copy link
Contributor Author

Updated the mergeDeep function with a safe option that we can use in the non-critical code paths.

var newTo = to;
if (safe) {
newTo = {};
for (key in to) {
Copy link
Member

Choose a reason for hiding this comment

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

minor: move var key; on line 14 earlier

- Add safe option to mergeDeep that prevents mutation from to object
- Use safe option in non-hot code paths
@mridgway mridgway force-pushed the fixMultiValueSettingOverride branch from bbefd32 to 24ab28e Compare May 13, 2016 00:44
@lingyan
Copy link
Member

lingyan commented May 13, 2016

🚢

@mridgway mridgway merged commit f4f9313 into master May 13, 2016
@mridgway mridgway deleted the fixMultiValueSettingOverride branch May 13, 2016 01:02
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.

4 participants