Skip to content

Commit 8c247e4

Browse files
committed
Update javascript-interface-library.ts
1 parent 87bddcc commit 8c247e4

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

src/javascript-interface-library.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,29 +1341,35 @@
13411341

13421342
/**** ValuesDiffer ****/
13431343

1344-
export function ValuesDiffer (thisValue:any, otherValue:any):boolean {
1344+
export function ValuesDiffer (
1345+
thisValue:any, otherValue:any, Mode?:'by-value'|'by-reference'|undefined
1346+
):boolean {
13451347
if (thisValue === otherValue) { return false }
13461348

13471349
let thisType = typeof thisValue
13481350
if (thisType !== typeof otherValue) { return true }
13491351

13501352
/**** ArraysDiffer ****/
13511353

1352-
function ArraysDiffer (thisArray:any[], otherArray:any[]):boolean {
1354+
function ArraysDiffer (
1355+
thisArray:any[], otherArray:any[], Mode:'by-value'|'by-reference'|undefined
1356+
):boolean {
13531357
if (! Array.isArray(otherArray)) { return true }
13541358

13551359
if (thisArray.length !== otherArray.length) { return true }
13561360

13571361
for (let i = 0, l = thisArray.length; i < l; i++) {
1358-
if (ValuesDiffer(thisArray[i],otherArray[i])) { return true }
1362+
if (ValuesDiffer(thisArray[i],otherArray[i],Mode)) { return true }
13591363
}
13601364

13611365
return false
13621366
}
13631367

13641368
/**** ObjectsDiffer ****/
13651369

1366-
function ObjectsDiffer (thisObject:any, otherObject:any):boolean {
1370+
function ObjectsDiffer (
1371+
thisObject:any, otherObject:any, Mode:'by-value'|'by-reference'|undefined
1372+
):boolean {
13671373
if (Object.getPrototypeOf(thisObject) !== Object.getPrototypeOf(otherObject)) {
13681374
return true
13691375
}
@@ -1375,7 +1381,7 @@
13751381
for (let key in otherObject) {
13761382
if (! (key in thisObject)) { return true }
13771383

1378-
if (ValuesDiffer(thisObject[key],otherObject[key])) {
1384+
if (ValuesDiffer(thisObject[key],otherObject[key],Mode)) {
13791385
return true
13801386
}
13811387
}
@@ -1396,11 +1402,23 @@
13961402
if (thisValue == null) { return true } // since "other_value" != null!
13971403
if (otherValue == null) { return true } // since "this_value" != null!
13981404

1405+
if ((Mode === 'by-value') && (
1406+
(thisValue instanceof Boolean) ||
1407+
(thisValue instanceof Number) ||
1408+
(thisValue instanceof String)
1409+
)) {
1410+
return (thisValue.valueOf() !== otherValue.valueOf())
1411+
}
1412+
13991413
if (Array.isArray(thisValue)) {
1400-
return ArraysDiffer(thisValue,otherValue)
1414+
return ArraysDiffer(thisValue,otherValue,Mode)
14011415
}
14021416

1403-
return ObjectsDiffer(thisValue,otherValue)
1417+
return (
1418+
Mode === 'by-reference'
1419+
? true // because (thisValue !== otherValue)
1420+
: ObjectsDiffer(thisValue,otherValue,Mode)
1421+
)
14041422
default: return true // unsupported property type
14051423
}
14061424

@@ -1409,8 +1427,10 @@
14091427

14101428
/**** ValuesAreEqual ****/
14111429

1412-
export function ValuesAreEqual (thisValue:any, otherValue:any):boolean {
1413-
return ! ValuesDiffer(thisValue,otherValue)
1430+
export function ValuesAreEqual (
1431+
thisValue:any, otherValue:any, Mode?:'by-value'|'by-reference'|undefined
1432+
):boolean {
1433+
return ! ValuesDiffer(thisValue,otherValue,Mode)
14141434
}
14151435

14161436
/**** ObjectIsEmpty ****/

0 commit comments

Comments
 (0)