Permalink
Browse files

fix(EntityProxy): compare dates on their value to prevent false posit…

…ives on dirty checks
  • Loading branch information...
RWOverdijk committed Jan 11, 2018
1 parent 377ec15 commit 678729a562db6d54bb79558ed7bc5e6f5038ad98
Showing with 20 additions and 1 deletion.
  1. +20 −1 src/EntityProxy.ts
@@ -62,6 +62,25 @@ export class EntityProxy {
return expected[property];
}
/**
* Check if provided values for {property} are different. Performs special checks for all Date types.
*
* @param {string} property
* @param {Date} current
* @param {Date} next
*
* @returns {boolean}
*/
function areDifferent(property: string, current: Date, next: Date): Boolean {
const isDate = ['date', 'dateTime', 'datetime', 'time'].indexOf(mapping.getType(property)) > -1;
if (!isDate) {
return current !== next;
}
return (new Date(current)).toString() !== (new Date(next)).toString();
}
/**
* Check if value is a setDirty value.
*
@@ -206,7 +225,7 @@ export class EntityProxy {
if (!relations || !relations[property]) {
// We're proxying and the value changed. Register as dirty.
if (isProxyActive() && target[property] !== value) {
if (isProxyActive() && areDifferent(property, target[property], value)) {
unitOfWork.registerDirty(target, property);
}

0 comments on commit 678729a

Please sign in to comment.