Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
basic
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xrm
basic
Commits
fcdadc8b
Commit
fcdadc8b
authored
4 years ago
by
Sebastian Listl
Browse files
Options
Downloads
Patches
Plain Diff
Utils.clone support for Map, Set and Symbol properties
parent
092a9b3b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
process/Sql_lib/process.js
+5
-22
5 additions, 22 deletions
process/Sql_lib/process.js
process/Util_lib/process.js
+35
-8
35 additions, 8 deletions
process/Util_lib/process.js
with
40 additions
and
30 deletions
process/Sql_lib/process.js
+
5
−
22
View file @
fcdadc8b
...
...
@@ -801,8 +801,6 @@ function SqlBuilder (pAlias)
this
.
_where
=
{};
this
.
_initWhere
();
SqlBuilder
.
defineCanBuildSql
(
this
);
}
/**
...
...
@@ -823,6 +821,8 @@ SqlBuilder.checkCanBuildSql = function (pObject)
return
pObject
[
SqlBuilder
.
getCanBuildSqlSymbol
()];
}
SqlBuilder
.
defineCanBuildSql
(
SqlBuilder
.
prototype
);
/**
* Deep copies the SqlBuilder object and returns a new one.<br/>
* Use this if you want to add for example add additional parameters without modifying the current builder.
...
...
@@ -830,25 +830,7 @@ SqlBuilder.checkCanBuildSql = function (pObject)
*/
SqlBuilder
.
prototype
.
copy
=
function
()
{
var
newBuilder
=
_deepCopyByJson
(
this
,
new
SqlBuilder
());
return
newBuilder
;
// NOTE: this works only with simple data types.
// Here we only use strings, arrays, booleans and null, so this should work
function
_deepCopyByJson
(
pObject
,
pNewObject
)
{
// deep copy by using json
var
deepCopied
=
JSON
.
parse
(
JSON
.
stringify
(
pObject
));
// set the props of the new object to the deepCopied ones.
// without this all functions would be lost
for
(
let
prop
in
deepCopied
)
{
pNewObject
[
prop
]
=
deepCopied
[
prop
]
}
return
pNewObject
;
}
return
Utils
.
clone
(
this
);
}
// errors which are thrown by the SqlBuilder
...
...
@@ -3117,9 +3099,10 @@ SqlBuilder._CaseStatement = function ()
this
.
_whenThens
=
[];
this
.
_elseValue
=
null
;
this
.
_afterWhenMask
=
new
SqlBuilder
.
_CaseWhen
(
this
);
SqlBuilder
.
defineCanBuildSql
(
this
);
}
SqlBuilder
.
defineCanBuildSql
(
SqlBuilder
.
_CaseStatement
.
prototype
);
/**
* @param {String|String[]|SqlBuilder|PreparedSqlArray} [pFieldOrCond] If this is the only parameter, it is used as Subselect <br/>
* else it is used as Field. <br/>
...
...
This diff is collapsed.
Click to expand it.
process/Util_lib/process.js
+
35
−
8
View file @
fcdadc8b
...
...
@@ -53,7 +53,7 @@ Utils.isNullOrEmpty = function (pObject)
}
/**
* Creates a deep copy of the given object. Also works with arrays.
* Creates a deep copy of the given object. Also works with arrays
, maps and sets
.
*
* @param {Object} pObject the object to create a copy of
* @return {Object} the cloned object
...
...
@@ -69,7 +69,7 @@ Utils.isNullOrEmpty = function (pObject)
*
* logging.log(original.name != copy.name); //true
* logging.log(copy instanceof MyObject()); //true, prototypes are set correctly
* logging.log(copy.obj1 === copy.obj2); //true, relative object references are
kept
* logging.log(copy.obj1 === copy.obj2); //true, relative object references are
preserved
*/
Utils
.
clone
=
function
(
pObject
)
{
...
...
@@ -84,20 +84,47 @@ Utils.clone = function (pObject)
if
(
referenceMap
.
has
(
pObject
))
return
referenceMap
.
get
(
pObject
);
var
clonedObject
=
Array
.
isArray
(
pObject
)
?
[]
:
Object
.
create
(
Object
.
getPrototypeOf
(
pObject
));
//set the prototype of the given object
var
clonedObject
;
if
(
Array
.
isArray
(
pObject
))
clonedObject
=
[];
else
if
(
pObject
instanceof
Map
)
clonedObject
=
new
Map
();
else
if
(
pObject
instanceof
Set
)
clonedObject
=
new
Set
();
else
clonedObject
=
Object
.
create
(
Object
.
getPrototypeOf
(
pObject
));
//set the prototype of the given object
/* keeps track of all encountered objects and maps the original to the copy, this makes it possible to:
- have the same relative references in the copy as in the original
- copy cyclic references without error */
referenceMap
.
set
(
pObject
,
clonedObject
);
for
(
let
key
in
pObject
)
if
(
pObject
instanceof
Map
)
{
pObject
.
forEach
(
function
(
value
,
key
)
{
clonedObject
.
set
(
_clone
(
key
),
_clone
(
value
));
});
}
else
if
(
pObject
instanceof
Set
)
{
var
value
=
pObject
[
key
];
clonedObject
[
key
]
=
_clone
(
value
);
//Recursively (deep) copy for nested objects, including arrays
pObject
.
forEach
(
function
(
value
)
{
clonedObject
.
add
(
_clone
(
value
));
});
}
else
{
for
(
let
key
in
pObject
)
{
clonedObject
[
key
]
=
_clone
(
pObject
[
key
]);
//Recursively (deep) copy for nested objects, including arrays
}
}
Object
.
getOwnPropertySymbols
(
pObject
).
forEach
(
function
(
sym
)
{
clonedObject
[
sym
]
=
_clone
(
pObject
[
sym
]);
});
return
clonedObject
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment