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

Commit f99845b6 by Mick Hansen

Refactor

1 parent 78bb1a2a
Showing with 19 additions and 13 deletions
...@@ -203,17 +203,19 @@ module.exports = (function() { ...@@ -203,17 +203,19 @@ module.exports = (function() {
this.refreshAttributes(); this.refreshAttributes();
this.DAO.prototype.booleanValues = [] this._booleanAttributes = []
this.DAO.prototype.dateAttributes = [] this._dateAttributes = []
this.DAO.prototype.booleanValues = this._booleanAttributes
this.DAO.prototype.dateAttributes = this._dateAttributes
this.DAO.prototype.defaultValues = {} this.DAO.prototype.defaultValues = {}
this.DAO.prototype.validators = {} this.DAO.prototype.validators = {}
Utils._.each(this.rawAttributes, function (definition, name) { Utils._.each(this.rawAttributes, function (definition, name) {
if (((definition === DataTypes.BOOLEAN) || (definition.type === DataTypes.BOOLEAN))) { if (((definition === DataTypes.BOOLEAN) || (definition.type === DataTypes.BOOLEAN))) {
self.DAO.prototype.booleanValues.push(name); self._booleanAttributes.push(name);
} }
if (((definition === DataTypes.DATE) || (definition.type === DataTypes.DATE) || (definition.originalType === DataTypes.DATE))) { if (((definition === DataTypes.DATE) || (definition.type === DataTypes.DATE) || (definition.originalType === DataTypes.DATE))) {
self.DAO.prototype.dateAttributes.push(name); self._dateAttributes.push(name);
} }
if (definition.hasOwnProperty('defaultValue')) { if (definition.hasOwnProperty('defaultValue')) {
self.DAO.prototype.defaultValues[name] = Utils._.partial( self.DAO.prototype.defaultValues[name] = Utils._.partial(
...@@ -225,15 +227,19 @@ module.exports = (function() { ...@@ -225,15 +227,19 @@ module.exports = (function() {
} }
}) })
this.DAO.prototype._hasBooleanAttributes = !!this.DAO.prototype.booleanValues.length this._hasBooleanAttributes = !!this._booleanAttributes.length
this.DAO.prototype._isBooleanAttribute = Utils._.memoize(function (key) { this._isBooleanAttribute = Utils._.memoize(function (key) {
return self.DAO.prototype.booleanValues.indexOf(key) !== -1 return self._booleanAttributes.indexOf(key) !== -1
}) })
this.DAO.prototype._hasBooleanAttributes = this._hasBooleanAttributes
this.DAO.prototype._isBooleanAttribute = this._isBooleanAttribute
this.DAO.prototype._hasDateAttributes = !!this.DAO.prototype.dateAttributes.length this._hasDateAttributes = !!this._dateAttributes.length
this.DAO.prototype._isDateAttribute = Utils._.memoize(function (key) { this._isDateAttribute = Utils._.memoize(function (key) {
return self.DAO.prototype.dateAttributes.indexOf(key) !== -1 return self._dateAttributes.indexOf(key) !== -1
}) })
this.DAO.prototype._hasDateAttributes = this._hasDateAttributes
this.DAO.prototype._isDateAttribute = this._isDateAttribute
this.DAO.prototype.__factory = this this.DAO.prototype.__factory = this
this.DAO.prototype.daoFactory = this this.DAO.prototype.daoFactory = this
......
...@@ -123,7 +123,7 @@ module.exports = (function() { ...@@ -123,7 +123,7 @@ module.exports = (function() {
} }
// If raw, and we're not dealing with includes, just set it straight on the dataValues object // If raw, and we're not dealing with includes, just set it straight on the dataValues object
if (options.raw && !(this.options && this.options.include) && !this._hasBooleanAttributes) { if (options.raw && !(this.options && this.options.include) && !this.Model._hasBooleanAttributes) {
if (Object.keys(this.dataValues).length) { if (Object.keys(this.dataValues).length) {
this.dataValues = _.extend(this.dataValues, values) this.dataValues = _.extend(this.dataValues, values)
} else { } else {
...@@ -188,7 +188,7 @@ module.exports = (function() { ...@@ -188,7 +188,7 @@ module.exports = (function() {
DAO.prototype.changed = function(key) { DAO.prototype.changed = function(key) {
if (key) { if (key) {
if (this._isDateAttribute(key) && this._previousDataValues[key] && this.dataValues[key]) { if (this.Model._isDateAttribute(key) && this._previousDataValues[key] && this.dataValues[key]) {
return this._previousDataValues[key].valueOf() !== this.dataValues[key].valueOf() return this._previousDataValues[key].valueOf() !== this.dataValues[key].valueOf()
} }
return this._previousDataValues[key] !== this.dataValues[key] return this._previousDataValues[key] !== this.dataValues[key]
...@@ -356,7 +356,7 @@ module.exports = (function() { ...@@ -356,7 +356,7 @@ module.exports = (function() {
args = [self, self.QueryInterface.QueryGenerator.addSchema(self.Model), values, options] args = [self, self.QueryInterface.QueryGenerator.addSchema(self.Model), values, options]
hook = 'Create' hook = 'Create'
} else { } else {
var identifier = self.__options.hasPrimaryKeys ? self.primaryKeyValues : { id: self.id } var identifier = self.primaryKeyValues
if (identifier === null && self.__options.whereCollection !== null) { if (identifier === null && self.__options.whereCollection !== null) {
identifier = self.__options.whereCollection; identifier = self.__options.whereCollection;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!