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

Commit 910cd0c1 by Sascha Depold

added success and failure jqXHR-like accessor

1 parent d7ea69af
...@@ -18,5 +18,18 @@ module.exports = (function() { ...@@ -18,5 +18,18 @@ module.exports = (function() {
return this return this
} }
CustomEventEmitter.prototype.success = CustomEventEmitter.prototype.ok = function(fct) {
this.success(fct)
return this
}
CustomEventEmitter.prototype.failure =
CustomEventEmitter.prototype.fail =
CustomEventEmitter.prototype.error =
function(fct) {
this.on('failure', fct)
return this
}
return CustomEventEmitter return CustomEventEmitter
})() })()
...@@ -34,14 +34,14 @@ module.exports = (function() { ...@@ -34,14 +34,14 @@ module.exports = (function() {
var eventEmitter = new Utils.CustomEventEmitter(function() { var eventEmitter = new Utils.CustomEventEmitter(function() {
var doQuery = function() { var doQuery = function() {
query.call(self, self.QueryGenerator.createTableQuery(self.tableName, self.attributes, options)) query.call(self, self.QueryGenerator.createTableQuery(self.tableName, self.attributes, options))
.on('success', function() { eventEmitter.emit('success', self) }) .success(function() { eventEmitter.emit('success', self) })
.on('failure', function(err) { eventEmitter.emit('failure', err) }) .error(function(err) { eventEmitter.emit('failure', err) })
} }
if(options.force) { if(options.force) {
self.drop() self.drop()
.on('success', function() { doQuery() }) .success(function() { doQuery() })
.on('failure', function(err) { eventEmitter.emit('failure', err) }) .error(function(err) { eventEmitter.emit('failure', err) })
} else { } else {
doQuery() doQuery()
} }
......
...@@ -27,6 +27,16 @@ module.exports = (function() { ...@@ -27,6 +27,16 @@ module.exports = (function() {
return this return this
} }
Query.prototype.success = Query.prototype.ok = function(fct) {
this.success(fct)
return this
}
Query.prototype.failure = Query.prototype.fail = Query.prototype.error = function(fct) {
this.on('failure', fct)
return this
}
//private //private
var bindClient = function() { var bindClient = function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!