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

Commit 7cf8e14b by sdepold

use error event instead of failure

1 parent 74a0ef95
......@@ -20,7 +20,7 @@ module.exports = (function() {
where[self.__factory.connectorDAO.tableName+"."+foreignKey] = {join: self.__factory.target.tableName+".id"}
self.__factory.target.findAllJoin(self.__factory.connectorDAO.tableName, {where: where})
.on('success', function(objects) { customEventEmitter.emit('success', objects) })
.on('failure', function(err){ customEventEmitter.emit('failure', err) })
.on('error', function(err){ customEventEmitter.emit('error', err) })
.on('sql', function(sql) { customEventEmitter.emit('sql', sql)})
})
......@@ -31,7 +31,7 @@ module.exports = (function() {
var self = this
destroyObsoleteAssociations.call(this, oldAssociations, newAssociations)
.error(function(err) { emitter.emit('failure', err) })
.error(function(err) { emitter.emit('error', err) })
.on('sql', function(sql) { emitter.emit('sql', sql) })
.success(function() {
var chainer = new Utils.QueryChainer
......@@ -50,7 +50,7 @@ module.exports = (function() {
chainer
.run()
.success(function() { emitter.emit('success', newAssociations) })
.error(function(err) { emitter.emit('failure', err) })
.error(function(err) { emitter.emit('error', err) })
.on('sql', function(sql) { emitter.emit('sql', sql) })
})
}
......@@ -84,7 +84,7 @@ module.exports = (function() {
chainer
.run()
.success(function() { emitter.emit('success', null) })
.error(function(err) { emitter.emit('failure', err) })
.error(function(err) { emitter.emit('error', err) })
.on('sql', function(sql) { emitter.emit('sql', sql) })
}
})
......
......@@ -31,7 +31,7 @@ module.exports = (function() {
chainer
.run()
.success(function() { emitter.emit('success', newAssociations) })
.error(function(err) { emitter.emit('failure', err) })
.error(function(err) { emitter.emit('error', err) })
}
return HasManySingleLinked
......
......@@ -24,8 +24,8 @@ module.exports = (function() {
set: Utils._.camelize('set_' + as),
add: Utils._.camelize(Utils.singularize('add_' + as)),
remove: Utils._.camelize(Utils.singularize('remove_' + as)),
hasSingle: Utils._.camelize(Utils.singularize('has_' + as)),
hasAll: Utils._.camelize('has_' + as)
hasSingle: Utils._.camelize(Utils.singularize('has_' + as)),
hasAll: Utils._.camelize('has_' + as)
}
}
......@@ -73,44 +73,44 @@ module.exports = (function() {
var Class = self.connectorDAO ? HasManyMultiLinked : HasManySingleLinked
return new Class(self, this).injectGetter()
}
obj[this.accessors.hasAll] = function(objects) {
var instance = this;
obj[this.accessors.hasAll] = function(objects) {
var instance = this;
var customEventEmitter = new Utils.CustomEventEmitter(function() {
instance[self.accessors.get]()
.error(function(err){ customEventEmitter.emit('failure', err)})
.success(function(associatedObjects) {
customEventEmitter.emit('success',
Utils._.all(objects, function(o) {
return Utils._.any(associatedObjects, function(associatedObject) {
return Utils._.all(associatedObject.identifiers, function(key, identifier) {
return o[identifier] == associatedObject[identifier];
});
})
})
)
})
.error(function(err){ customEventEmitter.emit('error', err)})
.success(function(associatedObjects) {
customEventEmitter.emit('success',
Utils._.all(objects, function(o) {
return Utils._.any(associatedObjects, function(associatedObject) {
return Utils._.all(associatedObject.identifiers, function(key, identifier) {
return o[identifier] == associatedObject[identifier];
});
})
})
)
})
})
return customEventEmitter.run()
}
obj[this.accessors.hasSingle] = function(o) {
var instance = this;
}
obj[this.accessors.hasSingle] = function(o) {
var instance = this;
var customEventEmitter = new Utils.CustomEventEmitter(function() {
instance[self.accessors.get]()
.error(function(err){ customEventEmitter.emit('failure', err)})
.success(function(associatedObjects) {
customEventEmitter.emit('success',
Utils._.any(associatedObjects, function(associatedObject) {
return Utils._.all(associatedObject.identifiers, function(key, identifier) {
return o[identifier] == associatedObject[identifier];
});
})
)
})
.error(function(err){ customEventEmitter.emit('error', err)})
.success(function(associatedObjects) {
customEventEmitter.emit('success',
Utils._.any(associatedObjects, function(associatedObject) {
return Utils._.all(associatedObject.identifiers, function(key, identifier) {
return o[identifier] == associatedObject[identifier];
});
})
)
})
})
return customEventEmitter.run()
}
}
return this
}
......@@ -134,14 +134,14 @@ module.exports = (function() {
var instance = this
var customEventEmitter = new Utils.CustomEventEmitter(function() {
instance[self.accessors.get]()
.error(function(err){ customEventEmitter.emit('failure', err)})
.error(function(err){ customEventEmitter.emit('error', err)})
.success(function(currentAssociatedObjects) {
if(!newAssociatedObject.equalsOneOf(currentAssociatedObjects))
currentAssociatedObjects.push(newAssociatedObject)
instance[self.accessors.set](currentAssociatedObjects)
.success(function(instances) { customEventEmitter.emit('success', instances) })
.error(function(err) { customEventEmitter.emit('failure', err) })
.error(function(err) { customEventEmitter.emit('error', err) })
})
})
return customEventEmitter.run()
......@@ -160,7 +160,7 @@ module.exports = (function() {
instance[self.accessors.set](newAssociations)
.success(function() { customEventEmitter.emit('success', null) })
.error(function(err) { customEventEmitter.emit('failure', err) })
.error(function(err) { customEventEmitter.emit('error', err) })
})
})
return customEventEmitter.run()
......
......@@ -60,7 +60,7 @@ module.exports = (function() {
associatedObject[self.identifier] = obj.id
associatedObject.save()
.success(function() { customEventEmitter.emit('success', associatedObject) })
.error(function(err) { customEventEmitter.emit('failure', err) })
.error(function(err) { customEventEmitter.emit('error', err) })
})
})
return customEventEmitter.run()
......@@ -70,4 +70,4 @@ module.exports = (function() {
}
return HasOne
})()
\ No newline at end of file
})()
......@@ -68,12 +68,12 @@ module.exports = (function() {
self.QueryInterface
.createTable(self.tableName, self.attributes, options)
.success(function() { emitter.emit('success', self) })
.error(function(err) { emitter.emit('failure', err) })
.error(function(err) { emitter.emit('error', err) })
.on('sql', function(sql) { emitter.emit('sql', sql) })
}
if(options.force)
self.drop().success(doQuery).error(function(err) { emitter.emit('failure', err) })
self.drop().success(doQuery).error(function(err) { emitter.emit('error', err) })
else
doQuery()
......
......@@ -127,7 +127,7 @@ module.exports = (function() {
var self = this
this.pool.acquire(function(err, client) {
if (err) {
queueItem.query.emit('failure', err)
queueItem.query.emit('error', err)
return
}
//we set the client here, asynchronously, when getting a pooled connection
......
......@@ -90,7 +90,7 @@ module.exports = (function() {
var onFailure = function(err) {
unbindClient.call(this)
this.emit('failure', err, this.callee)
this.emit('error', err, this.callee)
}
return Query
......
......@@ -85,7 +85,7 @@ module.exports = (function() {
query.on('error', function(err) {
receivedError = true
self.emit('failure', err, self.callee)
self.emit('error', err, self.callee)
});
return this
......
......@@ -16,7 +16,7 @@ module.exports = (function() {
}
Query.prototype.failure = Query.prototype.fail = Query.prototype.error = function(fct) {
this.on('failure', fct)
this.on('error', fct)
return this
}
......
......@@ -108,7 +108,7 @@ module.exports = (function() {
}
var onFailure = function(err) {
this.emit('failure', err, this.callee)
this.emit('error', err, this.callee)
}
return Query
......
......@@ -29,14 +29,14 @@ module.exports = (function() {
CustomEventEmitter.prototype.fail =
CustomEventEmitter.prototype.error =
function(fct) {
this.on('failure', fct)
this.on('error', fct)
return this
}
CustomEventEmitter.prototype.done =
CustomEventEmitter.prototype.complete =
function(fct) {
this.on('failure', function(err) { fct(err, null) })
this.on('error', function(err) { fct(err, null) })
.on('success', function(result) { fct(null, result) })
return this
}
......
......@@ -11,7 +11,7 @@ module.exports = (function(){
NullEmitter.prototype.emitNull = function() {
this.emit('success', null)
this.emit('failure', null)
this.emit('error', null)
}
return NullEmitter
......
......@@ -43,7 +43,7 @@ module.exports = (function() {
return new Utils.CustomEventEmitter(function(emitter) {
self.getUndoneMigrations(function(err, migrations) {
if(err) {
emitter.emit('failure', err)
emitter.emit('error', err)
} else {
var chainer = new Utils.QueryChainer
, from = migrations[0]
......@@ -75,7 +75,7 @@ module.exports = (function() {
chainer
.runSerially({ skipOnError: true })
.success(function() { emitter.emit('success', null) })
.error(function(err) { emitter.emit('failure', err) })
.error(function(err) { emitter.emit('error', err) })
}
})
}).run()
......@@ -152,7 +152,7 @@ module.exports = (function() {
SequelizeMeta
.sync(syncOptions || {})
.success(function() { emitter.emit('success', SequelizeMeta) })
.error(function(err) { emitter.emit('failure', err) })
.error(function(err) { emitter.emit('error', err) })
} else {
emitter.emit('success', SequelizeMeta)
}
......@@ -168,7 +168,7 @@ module.exports = (function() {
self.findOrCreateSequelizeMetaDAO().success(function(SequelizeMeta) {
SequelizeMeta.find({ order: 'id DESC' }).success(function(meta) {
emitter.emit('success', meta ? meta : null)
}).error(function(err) { emitter.emit('failure', err) })
}).error(function(err) { emitter.emit('error', err) })
}).error(function(err) { emitter.emit(err) })
}).run()
}
......@@ -182,7 +182,7 @@ module.exports = (function() {
emitter.emit('success', meta ? meta.to : null)
})
.error(function(err) {
emitter.emit('failure', err)
emitter.emit('error', err)
})
}).run()
}
......
......@@ -116,7 +116,7 @@ module.exports = (function() {
this.finished = (this.finishedEmits == this.serials.length)
if(this.finished && this.wasRunning) {
var status = (this.fails.length == 0 ? 'success' : 'failure')
var status = (this.fails.length == 0 ? 'success' : 'error')
, result = (this.fails.length == 0 ? result : this.fails)
this.eventEmitter.emit(status, result)
......
......@@ -48,11 +48,11 @@ module.exports = (function() {
})
.error(function(err) {
self.emit('dropAllTables', err)
emitter.emit('failure', err)
emitter.emit('error', err)
})
}).error(function(err) {
self.emit('dropAllTables', err)
emitter.emit('failure', err)
emitter.emit('error', err)
})
}).run()
}
......@@ -72,7 +72,7 @@ module.exports = (function() {
emitter.emit('success', Utils._.flatten(tableNames))
}).error(function(err) {
self.emit('showAllTables', err)
emitter.emit('failure', err)
emitter.emit('error', err)
})
}).run()
}
......@@ -90,7 +90,7 @@ module.exports = (function() {
self.sequelize.query(sql, null, { raw: true }).success(function(data) {
emitter.emit('success', data)
}).error(function(err) {
emitter.emit('failure', err)
emitter.emit('error', err)
})
}).run()
}
......@@ -153,11 +153,11 @@ module.exports = (function() {
emitter.emit('success', null)
}).error(function(err) {
self.emit('renameColumn', err)
emitter.emit('failure', err)
emitter.emit('error', err)
})
}).error(function(err) {
self.emit('renameColumn', err)
emitter.emit('failure', err)
emitter.emit('error', err)
})
}).run()
}
......@@ -217,7 +217,7 @@ module.exports = (function() {
})
.error(function(err) {
self.emit('rawSelect', err)
emitter.emit('failure', err)
emitter.emit('error', err)
})
qry.on('sql', function(sql) {
emitter.emit('sql', sql)
......@@ -253,7 +253,7 @@ module.exports = (function() {
}).error(function(err) {
options.error && options.error(err)
self.emit(methodName, err)
emitter.emit('failure', err)
emitter.emit('error', err)
})
query.on('sql', function(sql) {
emitter.emit('sql', sql)
......
......@@ -115,7 +115,7 @@ module.exports = (function() {
chainer
.run()
.success(function() { emitter.emit('success', null) })
.error(function(err) { emitter.emit('failure', err) })
.error(function(err) { emitter.emit('error', err) })
}).run()
}
......@@ -130,7 +130,7 @@ module.exports = (function() {
chainer
.run()
.success(function() { emitter.emit('success', null) })
.error(function(err) { emitter.emit('failure', err) })
.error(function(err) { emitter.emit('error', err) })
}).run()
}
......
......@@ -16,7 +16,7 @@ Factories.prototype.DAO = function(daoName, options, callback, count) {
DAO.create(options).on('success', function(dao) {
daos.push(dao)
cb && cb()
}).on('failure', function(err) {
}).on('error', function(err) {
console.log(err)
done()
})
......
......@@ -21,7 +21,7 @@ Helpers.prototype.drop = function() {
self.sequelize
.drop()
.on('success', done)
.on('failure', function(err) { console.log(err) })
.on('error', function(err) { console.log(err) })
})
}
......
......@@ -161,7 +161,7 @@ describe('DAOFactory', function() {
User.all().on('success', function(users) {
done()
expect(users.length).toEqual(2)
}).on('failure', function(err) { console.log(err) })
}).on('error', function(err) { console.log(err) })
})
})
})
......
......@@ -16,7 +16,7 @@ Factories.prototype.DAO = function(daoName, options, callback, count) {
DAO.create(options).on('success', function(dao) {
daos.push(dao)
cb && cb()
}).on('failure', function(err) {
}).on('error', function(err) {
console.log(err)
done()
})
......
......@@ -21,7 +21,7 @@ Helpers.prototype.drop = function() {
self.sequelize
.drop()
.on('success', done)
.on('failure', function(err) { console.log(err) })
.on('error', function(err) { console.log(err) })
})
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!