mirror of
https://github.com/Radarr/Radarr
synced 2024-12-25 17:27:59 +00:00
converted underscore.mixin.deepExtend to proper AMD module.
This commit is contained in:
parent
28a919e74a
commit
e0aceb98d2
1 changed files with 96 additions and 86 deletions
|
@ -3,9 +3,14 @@
|
||||||
*
|
*
|
||||||
* Based on https://gist.github.com/echong/3861963
|
* Based on https://gist.github.com/echong/3861963
|
||||||
*/
|
*/
|
||||||
(function() {
|
define(
|
||||||
var arrays, basicObjects, deepClone, deepExtend, deepExtendCouple, isBasicObject,
|
[
|
||||||
__slice = [].slice;
|
'underscore'
|
||||||
|
], function (_) {
|
||||||
|
|
||||||
|
var arrays, basicObjects, deepClone, deepExtend, deepExtendCouple, isBasicObject, __slice =
|
||||||
|
[
|
||||||
|
].slice;
|
||||||
|
|
||||||
deepClone = function (obj) {
|
deepClone = function (obj) {
|
||||||
var func, isArr;
|
var func, isArr;
|
||||||
|
@ -25,16 +30,21 @@
|
||||||
func = function (memo, value, key) {
|
func = function (memo, value, key) {
|
||||||
if (isArr) {
|
if (isArr) {
|
||||||
memo.push(deepClone(value));
|
memo.push(deepClone(value));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
memo[key] = deepClone(value);
|
memo[key] = deepClone(value);
|
||||||
}
|
}
|
||||||
return memo;
|
return memo;
|
||||||
};
|
};
|
||||||
return _.reduce(obj, func, isArr ? [] : {});
|
return _.reduce(obj, func, isArr ?
|
||||||
|
[
|
||||||
|
] :{});
|
||||||
};
|
};
|
||||||
|
|
||||||
isBasicObject = function (object) {
|
isBasicObject = function (object) {
|
||||||
if (object == null) return false;
|
if (object == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return (object.prototype === {}.prototype || object.prototype === Object.prototype) && _.isObject(object) && !_.isArray(object) && !_.isFunction(object) && !_.isDate(object) && !_.isRegExp(object) && !_.isArguments(object);
|
return (object.prototype === {}.prototype || object.prototype === Object.prototype) && _.isObject(object) && !_.isArray(object) && !_.isFunction(object) && !_.isDate(object) && !_.isRegExp(object) && !_.isArguments(object);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -80,7 +90,9 @@
|
||||||
|
|
||||||
deepExtend = function () {
|
deepExtend = function () {
|
||||||
var finalObj, maxDepth, objects, _i;
|
var finalObj, maxDepth, objects, _i;
|
||||||
objects = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), maxDepth = arguments[_i++];
|
objects = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) :(_i = 0,
|
||||||
|
[
|
||||||
|
]), maxDepth = arguments[_i++];
|
||||||
if (!_.isNumber(maxDepth)) {
|
if (!_.isNumber(maxDepth)) {
|
||||||
objects.push(maxDepth);
|
objects.push(maxDepth);
|
||||||
maxDepth = 20;
|
maxDepth = 20;
|
||||||
|
@ -98,7 +110,6 @@
|
||||||
return finalObj;
|
return finalObj;
|
||||||
};
|
};
|
||||||
|
|
||||||
require(['underscore'], function (_) {
|
|
||||||
|
|
||||||
_.mixin({
|
_.mixin({
|
||||||
deepClone : deepClone,
|
deepClone : deepClone,
|
||||||
|
@ -109,4 +120,3 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}).call(this);
|
|
||||||
|
|
Loading…
Reference in a new issue