Merge pull request #5392 from chrootsu/lodash-cloneDeep

lodash: changed _.cloneDeep() method
This commit is contained in:
Masahiro Wakame
2015-08-17 23:45:24 +09:00
2 changed files with 83 additions and 27 deletions

View File

@@ -1091,6 +1091,42 @@ helloWrap2();
* Lang *
********/
// _.cloneDeep
interface TestCloneDeepFn {
(value: any): any;
}
var testCloneDeepFn: TestCloneDeepFn;
result = <number>_.cloneDeep<number>(1);
result = <number>_.cloneDeep<number>(1, testCloneDeepFn);
result = <number>_.cloneDeep<number>(1, testCloneDeepFn, any);
result = <string>_.cloneDeep<string>('a');
result = <string>_.cloneDeep<string>('a', testCloneDeepFn);
result = <string>_.cloneDeep<string>('a', testCloneDeepFn, any);
result = <boolean>_.cloneDeep<boolean>(true);
result = <boolean>_.cloneDeep<boolean>(true, testCloneDeepFn);
result = <boolean>_.cloneDeep<boolean>(true, testCloneDeepFn, any);
result = <number[]>_.cloneDeep<number[]>([1, 2]);
result = <number[]>_.cloneDeep<number[]>([1, 2], testCloneDeepFn);
result = <number[]>_.cloneDeep<number[]>([1, 2], testCloneDeepFn, any);
result = <{a: {b: number;}}>_.cloneDeep<{a: {b: number;}}>({a: {b: 2}});
result = <{a: {b: number;}}>_.cloneDeep<{a: {b: number;}}>({a: {b: 2}}, testCloneDeepFn);
result = <{a: {b: number;}}>_.cloneDeep<{a: {b: number;}}>({a: {b: 2}}, testCloneDeepFn, any);
result = <number>_(1).cloneDeep();
result = <number>_(1).cloneDeep(testCloneDeepFn);
result = <number>_(1).cloneDeep(testCloneDeepFn, any);
result = <string>_('a').cloneDeep();
result = <string>_('a').cloneDeep(testCloneDeepFn);
result = <string>_('a').cloneDeep(testCloneDeepFn, any);
result = <boolean>_(true).cloneDeep();
result = <boolean>_(true).cloneDeep(testCloneDeepFn);
result = <boolean>_(true).cloneDeep(testCloneDeepFn, any);
result = <number[]>_([1, 2]).cloneDeep();
result = <number[]>_([1, 2]).cloneDeep(testCloneDeepFn);
result = <number[]>_([1, 2]).cloneDeep(testCloneDeepFn, any);
result = <{a: {b: number;}}>_({a: {b: 2}}).cloneDeep();
result = <{a: {b: number;}}>_({a: {b: 2}}).cloneDeep(testCloneDeepFn);
result = <{a: {b: number;}}>_({a: {b: 2}}).cloneDeep(testCloneDeepFn, any);
// _.gt
result = <boolean>_.gt(1, 2);
result = <boolean>_(1).gt(2);
@@ -1232,11 +1268,6 @@ result = <any>_.clone(stoogesAges, true, function (value) {
return _.isElement(value) ? value.cloneNode(false) : undefined;
});
result = <IStoogesAge[]>_.cloneDeep(stoogesAges);
result = <IStoogesAge[]>_.cloneDeep(stoogesAges, function (value) {
return _.isElement(value) ? value.cloneNode(false) : undefined;
});
interface Food {
name: string;
type: string;

69
lodash/lodash.d.ts vendored
View File

@@ -5997,6 +5997,53 @@ declare module _ {
* Lang *
********/
//_.cloneDeep
interface LoDashStatic {
/**
* Creates a deep clone of value. If customizer is provided its invoked to produce the cloned values. If
* customizer returns undefined cloning is handled by the method instead. The customizer is bound to thisArg
* and invoked with up to three argument; (value [, index|key, object]).
* Note: This method is loosely based on the structured clone algorithm. The enumerable properties of arguments
* objects and objects created by constructors other than Object are cloned to plain Object objects. An empty
* object is returned for uncloneable values such as functions, DOM nodes, Maps, Sets, and WeakMaps.
* @param value The value to deep clone.
* @param callback The function to customize cloning values.
* @param thisArg The this binding of customizer.
* @return Returns the deep cloned value.
*/
cloneDeep<T>(
value: T,
callback?: (value: any) => any,
thisArg?: any): T;
}
interface LoDashWrapper<T> {
/**
* @see _.cloneDeep
*/
cloneDeep(
callback?: (value: any) => any,
thisArg?: any): T;
}
interface LoDashArrayWrapper<T> {
/**
* @see _.cloneDeep
*/
cloneDeep(
callback?: (value: any) => any,
thisArg?: any): T[];
}
interface LoDashObjectWrapper<T> {
/**
* @see _.cloneDeep
*/
cloneDeep(
callback?: (value: any) => any,
thisArg?: any): T;
}
//_.gt
interface LoDashStatic {
/**
@@ -6469,28 +6516,6 @@ declare module _ {
thisArg?: any): T;
}
//_.cloneDeep
interface LoDashStatic {
/**
* Creates a deep clone of value. If a callback is provided it will be executed to produce the
* cloned values. If the callback returns undefined cloning will be handled by the method instead.
* The callback is bound to thisArg and invoked with one argument; (value).
*
* Note: This method is loosely based on the structured clone algorithm. Functions and DOM nodes
* are not cloned. The enumerable properties of arguments objects and objects created by constructors
* other than Object are cloned to plain Object objects.
* See http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm.
* @param value The value to clone.
* @param callback The function to customize cloning values.
* @param thisArg The this binding of callback.
* @return The cloned value.
**/
cloneDeep<T>(
value: T,
callback?: (value: any) => any,
thisArg?: any): T;
}
//_.defaults
interface LoDashStatic {
/**