不要怂,就是干,撸起袖子干!

Commit a9524acf by Michael Storgaard

Renamed areChanged to didChange and added support for underscore in setter

1 parent 2f17a525
Showing with 10 additions and 6 deletions
......@@ -87,7 +87,7 @@ module.exports = (function() {
DAO.prototype.get = DAO.prototype.getDataValue
DAO.prototype.setDataValue = function(name, value) {
if (Utils.areChanged(this.dataValues[name], value)) {
if (Utils.didChange(this.dataValues[name], value)) {
this.isDirty = true
}
this.dataValues[name] = value
......@@ -240,7 +240,7 @@ module.exports = (function() {
(self.attributes.indexOf(attr) > -1)
)
if (updateAllowed) {
if (Utils.areChanged(self[attr], value)) {
if (Utils.didChange(self[attr], value)) {
isDirty = true
}
self[attr] = value
......@@ -346,9 +346,13 @@ module.exports = (function() {
if (has !== true) {
this.__defineGetter__(attribute, has.get || function() { return this.dataValues[attribute]; });
this.__defineSetter__(attribute, has.set || function(v) {
if (Utils.areChanged(this.dataValues[attribute], v)) {
if (Utils.didChange(this.dataValues[attribute], v)) {
//Only dirty the object if the change is not due to id, touchedAt, createdAt or updatedAt being initiated
if (this.dataValues[attribute] || (attribute != 'id' && attribute != 'touchedAt' && attribute != 'createdAt' && attribute != 'updatedAt')) {
var updatedAtAttr = this.__options.underscored ? 'updated_at' : 'updatedAt'
, createdAtAttr = this.__options.underscored ? 'created_at' : 'createdAt'
, touchedAtAttr = this.__options.underscored ? 'touched_at' : 'touchedAt'
if (this.dataValues[attribute] || (attribute != 'id' && attribute != touchedAtAttr && attribute != createdAtAttr && attribute != updatedAtAttr)) {
this.isDirty = true
}
}
......
......@@ -252,7 +252,7 @@ var Utils = module.exports = {
isHash: function(obj) {
return Utils._.isObject(obj) && !Array.isArray(obj);
},
areChanged: function(attrValue, value) {
didChange: function(attrValue, value) {
//If attribute value is Date, check value as a date
if (Utils._.isDate(attrValue) && !Utils._.isDate(value)) {
value = new Date(value)
......@@ -260,7 +260,7 @@ var Utils = module.exports = {
if (Utils._.isDate(attrValue)) {
return attrValue.valueOf() !== value.valueOf()
}
//If both are them are empty, don't set as changed
//If both of them are empty, don't set as changed
if ((attrValue === undefined || attrValue === null || attrValue === '') && (value === undefined || value === null || value === '')) {
return false
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!