1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

backward compatible equality testing of immutables

- make non object equality tests non strict
- this aligns with prior condition
This commit is contained in:
Stephen McLaughlin 2022-03-10 11:22:59 +00:00 committed by GitHub
parent 10f77fdf1a
commit 73ff852648
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -138,22 +138,17 @@
} }
} }
}); });
/** /**
* Compares `newValue` with `originalValue` for equality. * Compares `newValue` with `originalValue` for equality.
* NOTES:
* * If `newValue` is a string or number, comparison is not strict
* * If `newValue` is anything else, comparison is strict
* @param {*} originalValue Original value * @param {*} originalValue Original value
* @param {*} newValue New value * @param {*} newValue New value
* @returns {boolean} true if originalValue equals newValue, otherwise false * @returns {boolean} true if originalValue equals newValue, otherwise false
*/ */
function isEqual(originalValue, newValue) { function isEqual(originalValue, newValue) {
try { try {
if (typeof newValue === "string" || typeof newValue === "number") { if(originalValue == newValue) {
return originalValue == newValue; return true;
}
if (typeof newValue === "boolean") {
return originalValue === newValue;
} }
return JSON.stringify(originalValue) === JSON.stringify(newValue); return JSON.stringify(originalValue) === JSON.stringify(newValue);
} catch (err) { } catch (err) {