|
1341 | 1341 |
|
1342 | 1342 | /**** ValuesDiffer ****/ |
1343 | 1343 |
|
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 { |
1345 | 1347 | if (thisValue === otherValue) { return false } |
1346 | 1348 |
|
1347 | 1349 | let thisType = typeof thisValue |
1348 | 1350 | if (thisType !== typeof otherValue) { return true } |
1349 | 1351 |
|
1350 | 1352 | /**** ArraysDiffer ****/ |
1351 | 1353 |
|
1352 | | - function ArraysDiffer (thisArray:any[], otherArray:any[]):boolean { |
| 1354 | + function ArraysDiffer ( |
| 1355 | + thisArray:any[], otherArray:any[], Mode:'by-value'|'by-reference'|undefined |
| 1356 | + ):boolean { |
1353 | 1357 | if (! Array.isArray(otherArray)) { return true } |
1354 | 1358 |
|
1355 | 1359 | if (thisArray.length !== otherArray.length) { return true } |
1356 | 1360 |
|
1357 | 1361 | 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 } |
1359 | 1363 | } |
1360 | 1364 |
|
1361 | 1365 | return false |
1362 | 1366 | } |
1363 | 1367 |
|
1364 | 1368 | /**** ObjectsDiffer ****/ |
1365 | 1369 |
|
1366 | | - function ObjectsDiffer (thisObject:any, otherObject:any):boolean { |
| 1370 | + function ObjectsDiffer ( |
| 1371 | + thisObject:any, otherObject:any, Mode:'by-value'|'by-reference'|undefined |
| 1372 | + ):boolean { |
1367 | 1373 | if (Object.getPrototypeOf(thisObject) !== Object.getPrototypeOf(otherObject)) { |
1368 | 1374 | return true |
1369 | 1375 | } |
|
1375 | 1381 | for (let key in otherObject) { |
1376 | 1382 | if (! (key in thisObject)) { return true } |
1377 | 1383 |
|
1378 | | - if (ValuesDiffer(thisObject[key],otherObject[key])) { |
| 1384 | + if (ValuesDiffer(thisObject[key],otherObject[key],Mode)) { |
1379 | 1385 | return true |
1380 | 1386 | } |
1381 | 1387 | } |
|
1396 | 1402 | if (thisValue == null) { return true } // since "other_value" != null! |
1397 | 1403 | if (otherValue == null) { return true } // since "this_value" != null! |
1398 | 1404 |
|
| 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 | + |
1399 | 1413 | if (Array.isArray(thisValue)) { |
1400 | | - return ArraysDiffer(thisValue,otherValue) |
| 1414 | + return ArraysDiffer(thisValue,otherValue,Mode) |
1401 | 1415 | } |
1402 | 1416 |
|
1403 | | - return ObjectsDiffer(thisValue,otherValue) |
| 1417 | + return ( |
| 1418 | + Mode === 'by-reference' |
| 1419 | + ? true // because (thisValue !== otherValue) |
| 1420 | + : ObjectsDiffer(thisValue,otherValue,Mode) |
| 1421 | + ) |
1404 | 1422 | default: return true // unsupported property type |
1405 | 1423 | } |
1406 | 1424 |
|
|
1409 | 1427 |
|
1410 | 1428 | /**** ValuesAreEqual ****/ |
1411 | 1429 |
|
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) |
1414 | 1434 | } |
1415 | 1435 |
|
1416 | 1436 | /**** ObjectIsEmpty ****/ |
|
0 commit comments