hadron-document
Advanced tools
Comparing version 2.3.1 to 2.3.2
@@ -8,3 +8,5 @@ 'use strict'; | ||
const isEqual = require('lodash.isequal'); | ||
const isString = require('lodash.isstring'); | ||
const includes = require('lodash.includes'); | ||
const { ObjectId } = require('bson'); | ||
const Iterator = require('./iterator'); | ||
@@ -15,2 +17,4 @@ const ObjectGenerator = require('./object-generator'); | ||
const DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss.SSS'; | ||
/** | ||
@@ -305,3 +309,3 @@ * The event constant. | ||
return (this.key !== this.currentKey || | ||
!isEqual(this.value, this.currentValue) || | ||
!this._valuesEqual() || | ||
this.type !== this.currentType) && | ||
@@ -312,2 +316,22 @@ !this.isAdded(); | ||
/** | ||
* Check for value equality. | ||
*/ | ||
_valuesEqual() { | ||
if (this.currentType === 'Date' && isString(this.currentValue)) { | ||
return isEqual(this.value, new Date(this.currentValue)); | ||
} else if (this.currentType === 'ObjectID' && isString(this.currentValue)) { | ||
return this._isObjectIdEqual(); | ||
} | ||
return isEqual(this.value, this.currentValue); | ||
} | ||
_isObjectIdEqual() { | ||
try { | ||
return isEqual(this.value, ObjectId.createFromHexString(this.currentValue)); | ||
} catch (_) { | ||
return false; | ||
} | ||
} | ||
/** | ||
* Is the element the last in the elements. | ||
@@ -706,1 +730,2 @@ * | ||
module.exports.Events = Events; | ||
module.exports.DATE_FORMAT = DATE_FORMAT; |
@@ -7,3 +7,3 @@ { | ||
"homepage": "https://github.com/mongodb-js/hadron-document", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"repository": { | ||
@@ -27,2 +27,3 @@ "type": "git", | ||
"dependencies": { | ||
"bson": "^0.5.4", | ||
"debug": "^2.2.0", | ||
@@ -35,2 +36,3 @@ "hadron-type-checker": "^2.1.0", | ||
"lodash.isplainobject": "^4.0.4", | ||
"lodash.isstring": "^4.0.1", | ||
"lodash.keys": "^4.0.7", | ||
@@ -40,6 +42,6 @@ "uuid": "^3.0.0" | ||
"devDependencies": { | ||
"bson": "^0.5.4", | ||
"chai": "^3.4.1", | ||
"eslint-config-mongodb-js": "^2.2.0", | ||
"mocha": "^2.3.4", | ||
"moment": "^2.18.1", | ||
"mongodb-js-fmt": "^0.0.3", | ||
@@ -46,0 +48,0 @@ "mongodb-js-precommit": "^0.2.9", |
35466
910
11
+ Addedbson@^0.5.4
+ Addedlodash.isstring@^4.0.1
+ Addedbson@0.5.7(transitive)