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

Commit 9e17971f by Mick Hansen

chore: add deprecation warnings to event emitter style callbacks, closes #2280

1 parent d6c9e0d1
Showing with 10 additions and 1 deletions
...@@ -3,7 +3,13 @@ ...@@ -3,7 +3,13 @@
var Promise = require('sequelize-bluebird') var Promise = require('sequelize-bluebird')
, EventEmitter = require('events').EventEmitter , EventEmitter = require('events').EventEmitter
, proxyEventKeys = ['success', 'error', 'sql'] , proxyEventKeys = ['success', 'error', 'sql']
, Utils = require('./utils'); , Utils = require('./utils')
, seen = {}
, deprecated = function(message) {
if (seen[message]) return;
console.warn(message);
seen[message] = true;
};
/** /**
* A slightly modified version of bluebird promises. This means that, on top of the methods below, you can also call all the methods listed on the link below. * A slightly modified version of bluebird promises. This means that, on top of the methods below, you can also call all the methods listed on the link below.
...@@ -75,6 +81,7 @@ SequelizePromise.prototype.emit = function(evt) { ...@@ -75,6 +81,7 @@ SequelizePromise.prototype.emit = function(evt) {
*/ */
SequelizePromise.prototype.success = SequelizePromise.prototype.success =
SequelizePromise.prototype.ok = function(fct) { SequelizePromise.prototype.ok = function(fct) {
deprecated('EventEmitter#success|ok is deprecated, please use promise-style instead.');
if (fct.length > 1) { if (fct.length > 1) {
return this.spread(fct); return this.spread(fct);
} else { } else {
...@@ -100,6 +107,7 @@ SequelizePromise.prototype.ok = function(fct) { ...@@ -100,6 +107,7 @@ SequelizePromise.prototype.ok = function(fct) {
SequelizePromise.prototype.failure = SequelizePromise.prototype.failure =
SequelizePromise.prototype.fail = SequelizePromise.prototype.fail =
SequelizePromise.prototype.error = function(fct) { SequelizePromise.prototype.error = function(fct) {
deprecated('EventEmitter#failure|fail|error is deprecated, please use promise-style instead.');
return this.then(null, fct); return this.then(null, fct);
}; };
...@@ -126,6 +134,7 @@ SequelizePromise.prototype.complete = function(fct) { ...@@ -126,6 +134,7 @@ SequelizePromise.prototype.complete = function(fct) {
} }
if (fct.length > 2) { if (fct.length > 2) {
deprecated('EventEmitter#complete|done is deprecated, please use promise-style instead.');
return this.spread(function() { return this.spread(function() {
fct.apply(null, [null].concat(Array.prototype.slice.call(arguments))); fct.apply(null, [null].concat(Array.prototype.slice.call(arguments)));
}, fct); }, fct);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!