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

Commit a9ea2c57 by Sascha Depold

use new success binder

1 parent b445c871
...@@ -16,14 +16,14 @@ module.exports = (function() { ...@@ -16,14 +16,14 @@ module.exports = (function() {
var primaryKeys = Utils._.keys(self.__definition.connectorModel.rawAttributes) var primaryKeys = Utils._.keys(self.__definition.connectorModel.rawAttributes)
, foreignKey = primaryKeys.filter(function(pk) { return pk != self.__definition.identifier })[0] , foreignKey = primaryKeys.filter(function(pk) { return pk != self.__definition.identifier })[0]
self.__definition.connectorModel.findAll({where: where}).on('success', function(associatedObjects) { self.__definition.connectorModel.findAll({where: where}).success(function(associatedObjects) {
var ids = associatedObjects.map(function(obj) { return obj[foreignKey] }) var ids = associatedObjects.map(function(obj) { return obj[foreignKey] })
if (ids.length == 0) { if (ids.length == 0) {
customEventEmitter.emit('success', []) customEventEmitter.emit('success', [])
} else { } else {
self.__definition.target.findAll({where: 'id in (' + ids.join(", ") + ')'}) self.__definition.target.findAll({where: 'id in (' + ids.join(", ") + ')'})
.on('success', function(objects) { customEventEmitter.emit('success', objects) }) .success(function(objects) { customEventEmitter.emit('success', objects) })
.on('failure', function(err){ customEventEmitter.emit('failure', err) }) .on('failure', function(err){ customEventEmitter.emit('failure', err) })
} }
}) })
...@@ -37,7 +37,7 @@ module.exports = (function() { ...@@ -37,7 +37,7 @@ module.exports = (function() {
destroyObsoleteAssociations.call(this, oldAssociations, newAssociations) destroyObsoleteAssociations.call(this, oldAssociations, newAssociations)
.on('failure', function(err) { emitter.emit('failure', err) }) .on('failure', function(err) { emitter.emit('failure', err) })
.on('success', function() { .success(function() {
var chainer = new Utils.QueryChainer var chainer = new Utils.QueryChainer
, association = self.__definition.target.associations[self.__definition.associationAccessor] , association = self.__definition.target.associations[self.__definition.associationAccessor]
, foreignIdentifier = association.isSelfAssociation ? association.foreignIdentifier : association.identifier , foreignIdentifier = association.isSelfAssociation ? association.foreignIdentifier : association.identifier
...@@ -53,7 +53,7 @@ module.exports = (function() { ...@@ -53,7 +53,7 @@ module.exports = (function() {
chainer chainer
.run() .run()
.on('success', function() { emitter.emit('success', newAssociations) }) .success(function() { emitter.emit('success', newAssociations) })
.on('failure', function(err) { emitter.emit('failure', err) }) .on('failure', function(err) { emitter.emit('failure', err) })
}) })
} }
...@@ -79,14 +79,14 @@ module.exports = (function() { ...@@ -79,14 +79,14 @@ module.exports = (function() {
where[self.__definition.identifier] = self.instance.id where[self.__definition.identifier] = self.instance.id
where[foreignKey] = associatedObject.id where[foreignKey] = associatedObject.id
self.__definition.connectorModel.find({where: where}).on('success', function(connector) { self.__definition.connectorModel.find({where: where}).success(function(connector) {
chainer.add(connector.destroy()) chainer.add(connector.destroy())
if(chainer.emitters.length == obsoleteAssociations.length) { if(chainer.emitters.length == obsoleteAssociations.length) {
// found all obsolete connectors and will delete them now // found all obsolete connectors and will delete them now
chainer chainer
.run() .run()
.on('success', function() { emitter.emit('success', null) }) .success(function() { emitter.emit('success', null) })
.on('failure', function(err) { emitter.emit('failure', err) }) .on('failure', function(err) { emitter.emit('failure', err) })
} }
}) })
......
...@@ -30,7 +30,7 @@ module.exports = (function() { ...@@ -30,7 +30,7 @@ module.exports = (function() {
}) })
chainer chainer
.run() .run()
.on('success', function() { emitter.emit('success', newAssociations) }) .success(function() { emitter.emit('success', newAssociations) })
.on('failure', function(err) { emitter.emit('failure', err) }) .on('failure', function(err) { emitter.emit('failure', err) })
} }
......
...@@ -80,7 +80,7 @@ module.exports = (function() { ...@@ -80,7 +80,7 @@ module.exports = (function() {
// define the returned customEventEmitter, which will emit the success event once everything is done // define the returned customEventEmitter, which will emit the success event once everything is done
var customEventEmitter = new Utils.CustomEventEmitter(function() { var customEventEmitter = new Utils.CustomEventEmitter(function() {
instance[self.accessors.get]().on('success', function(oldAssociatedObjects) { instance[self.accessors.get]().success(function(oldAssociatedObjects) {
var Class = self.connectorModel ? HasManyMultiLinked : HasManySingleLinked var Class = self.connectorModel ? HasManyMultiLinked : HasManySingleLinked
new Class(self, instance).injectSetter(customEventEmitter, oldAssociatedObjects, newAssociatedObjects) new Class(self, instance).injectSetter(customEventEmitter, oldAssociatedObjects, newAssociatedObjects)
}) })
...@@ -93,12 +93,12 @@ module.exports = (function() { ...@@ -93,12 +93,12 @@ module.exports = (function() {
var customEventEmitter = new Utils.CustomEventEmitter(function() { var customEventEmitter = new Utils.CustomEventEmitter(function() {
instance[self.accessors.get]() instance[self.accessors.get]()
.on('failure', function(err){ customEventEmitter.emit('failure', err)}) .on('failure', function(err){ customEventEmitter.emit('failure', err)})
.on('success', function(currentAssociatedObjects) { .success(function(currentAssociatedObjects) {
if(!newAssociatedObject.equalsOneOf(currentAssociatedObjects)) if(!newAssociatedObject.equalsOneOf(currentAssociatedObjects))
currentAssociatedObjects.push(newAssociatedObject) currentAssociatedObjects.push(newAssociatedObject)
instance[self.accessors.set](currentAssociatedObjects) instance[self.accessors.set](currentAssociatedObjects)
.on('success', function(instances) { customEventEmitter.emit('success', instances) }) .success(function(instances) { customEventEmitter.emit('success', instances) })
.on('failure', function(err) { customEventEmitter.emit('failure', err) }) .on('failure', function(err) { customEventEmitter.emit('failure', err) })
}) })
}) })
...@@ -108,7 +108,7 @@ module.exports = (function() { ...@@ -108,7 +108,7 @@ module.exports = (function() {
obj[this.accessors.remove] = function(oldAssociatedObject) { obj[this.accessors.remove] = function(oldAssociatedObject) {
var instance = this var instance = this
var customEventEmitter = new Utils.CustomEventEmitter(function() { var customEventEmitter = new Utils.CustomEventEmitter(function() {
instance[self.accessors.get]().on('success', function(currentAssociatedObjects) { instance[self.accessors.get]().success(function(currentAssociatedObjects) {
var newAssociations = [] var newAssociations = []
currentAssociatedObjects.forEach(function(association) { currentAssociatedObjects.forEach(function(association) {
...@@ -117,7 +117,7 @@ module.exports = (function() { ...@@ -117,7 +117,7 @@ module.exports = (function() {
}) })
instance[self.accessors.set](newAssociations) instance[self.accessors.set](newAssociations)
.on('success', function() { customEventEmitter.emit('success', null) }) .success(function() { customEventEmitter.emit('success', null) })
.on('failure', function(err) { customEventEmitter.emit('failure', err) }) .on('failure', function(err) { customEventEmitter.emit('failure', err) })
}) })
}) })
......
...@@ -51,7 +51,7 @@ module.exports = (function() { ...@@ -51,7 +51,7 @@ module.exports = (function() {
obj[this.accessors.set] = function(associatedObject) { obj[this.accessors.set] = function(associatedObject) {
var customEventEmitter = new Utils.CustomEventEmitter(function() { var customEventEmitter = new Utils.CustomEventEmitter(function() {
obj[self.accessors.get]().on('success', function(oldObj) { obj[self.accessors.get]().success(function(oldObj) {
if(oldObj) { if(oldObj) {
oldObj[self.identifier] = null oldObj[self.identifier] = null
oldObj.save() oldObj.save()
...@@ -59,7 +59,7 @@ module.exports = (function() { ...@@ -59,7 +59,7 @@ module.exports = (function() {
associatedObject[self.identifier] = obj.id associatedObject[self.identifier] = obj.id
associatedObject.save() associatedObject.save()
.on('success', function() { customEventEmitter.emit('success', associatedObject) }) .success(function() { customEventEmitter.emit('success', associatedObject) })
.on('failure', function(err) { customEventEmitter.emit('failure', err) }) .on('failure', function(err) { customEventEmitter.emit('failure', err) })
}) })
}) })
......
...@@ -84,7 +84,7 @@ module.exports = (function() { ...@@ -84,7 +84,7 @@ module.exports = (function() {
var self = this var self = this
queueItem.query queueItem.query
.on('success', function(){ afterQuery.call(self, queueItem) }) .success(function(){ afterQuery.call(self, queueItem) })
.on('failure', function(){ afterQuery.call(self, queueItem) }) .on('failure', function(){ afterQuery.call(self, queueItem) })
queueItem.query.run(queueItem.sql) queueItem.query.run(queueItem.sql)
......
...@@ -19,7 +19,7 @@ module.exports = (function() { ...@@ -19,7 +19,7 @@ module.exports = (function() {
} }
CustomEventEmitter.prototype.success = CustomEventEmitter.prototype.ok = function(fct) { CustomEventEmitter.prototype.success = CustomEventEmitter.prototype.ok = function(fct) {
this.success(fct) this.on('success', fct)
return this return this
} }
......
...@@ -62,7 +62,7 @@ module.exports = (function() { ...@@ -62,7 +62,7 @@ module.exports = (function() {
var self = this var self = this
var emitter = new Utils.CustomEventEmitter(function() { var emitter = new Utils.CustomEventEmitter(function() {
query.call(self, self.QueryGenerator.countQuery(self.tableName, options), self, {plain: true}).on('success', function(obj) { query.call(self, self.QueryGenerator.countQuery(self.tableName, options), self, {plain: true}).success(function(obj) {
emitter.emit('success', obj['count(*)']) emitter.emit('success', obj['count(*)'])
}) })
}) })
...@@ -73,7 +73,7 @@ module.exports = (function() { ...@@ -73,7 +73,7 @@ module.exports = (function() {
var self = this var self = this
var emitter = new Utils.CustomEventEmitter(function() { var emitter = new Utils.CustomEventEmitter(function() {
query.call(self, self.QueryGenerator.maxQuery(self.tableName, field,options), self, {plain: true}).on('success', function(obj) { query.call(self, self.QueryGenerator.maxQuery(self.tableName, field,options), self, {plain: true}).success(function(obj) {
emitter.emit('success', obj['max']) emitter.emit('success', obj['max'])
}) })
}) })
...@@ -83,7 +83,7 @@ module.exports = (function() { ...@@ -83,7 +83,7 @@ module.exports = (function() {
var self = this var self = this
var emitter = new Utils.CustomEventEmitter(function() { var emitter = new Utils.CustomEventEmitter(function() {
query.call(self, self.QueryGenerator.minQuery(self.tableName, field,options), self, {plain: true}).on('success', function(obj) { query.call(self, self.QueryGenerator.minQuery(self.tableName, field,options), self, {plain: true}).success(function(obj) {
emitter.emit('success', obj['min']) emitter.emit('success', obj['min'])
}) })
}) })
......
...@@ -35,7 +35,7 @@ module.exports = (function() { ...@@ -35,7 +35,7 @@ module.exports = (function() {
var self = this var self = this
var eventEmitter = new Utils.CustomEventEmitter(function() { var eventEmitter = new Utils.CustomEventEmitter(function() {
query.call(self, self.QueryGenerator.insertQuery(self.__definition.tableName, self.values)) query.call(self, self.QueryGenerator.insertQuery(self.__definition.tableName, self.values))
.on('success', function(obj) { .success(function(obj) {
obj.isNewRecord = false obj.isNewRecord = false
eventEmitter.emit('success', obj) eventEmitter.emit('success', obj)
}) })
......
...@@ -36,7 +36,7 @@ module.exports = (function() { ...@@ -36,7 +36,7 @@ module.exports = (function() {
var observeEmitter = function(emitter) { var observeEmitter = function(emitter) {
var self = this var self = this
emitter emitter
.on('success', function(){ .success(function(){
self.finishedEmits++ self.finishedEmits++
finish.call(self) finish.call(self)
}) })
......
...@@ -28,7 +28,7 @@ module.exports = (function() { ...@@ -28,7 +28,7 @@ module.exports = (function() {
} }
Query.prototype.success = Query.prototype.ok = function(fct) { Query.prototype.success = Query.prototype.ok = function(fct) {
this.success(fct) this.on('success', fct)
return this return this
} }
......
...@@ -70,7 +70,7 @@ module.exports = (function() { ...@@ -70,7 +70,7 @@ module.exports = (function() {
chainer chainer
.run() .run()
.on('success', function() { eventEmitter.emit('success', null) }) .success(function() { eventEmitter.emit('success', null) })
.on('failure', function(err) { eventEmitter.emit('failure', err) }) .on('failure', function(err) { eventEmitter.emit('failure', err) })
}) })
return eventEmitter.run() return eventEmitter.run()
...@@ -86,7 +86,7 @@ module.exports = (function() { ...@@ -86,7 +86,7 @@ module.exports = (function() {
chainer chainer
.run() .run()
.on('success', function() { emitter.emit('success', null) }) .success(function() { emitter.emit('success', null) })
.on('failure', function(err) { emitter.emit('failure', err) }) .on('failure', function(err) { emitter.emit('failure', err) })
}).run() }).run()
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!