mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
Fixes some bugs from bulk renaming singleton object variables
Related to #128
This commit is contained in:
parent
91e0e7af3f
commit
45ea2dfba3
1 changed files with 2 additions and 2 deletions
56
app/Lib/Utilities/OptionsHelper.js
Normal file
56
app/Lib/Utilities/OptionsHelper.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
define([
|
||||
"Lib/Utilities/Exception"
|
||||
],
|
||||
|
||||
function (Exception) {
|
||||
|
||||
"use strict";
|
||||
|
||||
function OptionsHelper() {
|
||||
|
||||
}
|
||||
|
||||
OptionsHelper.prototype.merge = function(options, preset) {
|
||||
|
||||
if(!preset && !options) {
|
||||
throw new Exception("OptionsHelper requires objects");
|
||||
}
|
||||
|
||||
if(preset.constructor !== Object && options.constructor !== Object) {
|
||||
throw new Exception("OptionsHelper requires objects");
|
||||
}
|
||||
|
||||
if(!preset || preset.constructor !== Object) {
|
||||
return options;
|
||||
}
|
||||
|
||||
if(!options || options.constructor !== Object) {
|
||||
return preset;
|
||||
}
|
||||
|
||||
// FIXME there is a bad bug here, the preset is being manipulated by reference, so no config can be used!
|
||||
|
||||
// hotfix for the bug
|
||||
preset = JSON.parse(JSON.stringify(preset));
|
||||
|
||||
for (var key in options) {
|
||||
if(!preset.hasOwnProperty(key)) {
|
||||
preset[key] = options[key];
|
||||
} else {
|
||||
if(options[key] === undefined) {
|
||||
continue;
|
||||
}
|
||||
if(options[key].constructor !== Object) {
|
||||
preset[key] = options[key];
|
||||
} else {
|
||||
preset[key] = OptionsHelper.prototype.merge.call(this, options[key], preset[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return preset;
|
||||
}
|
||||
|
||||
return new OptionsHelper();
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue