Deprecate DAO events
List of deprecated events: - changed - deleted - deletedAll
This commit is contained in:
parent
03daaca9de
commit
37d7721e0e
|
@ -6,6 +6,7 @@ var inflection = require('inflection');
|
|||
var EventEmitter = require('events').EventEmitter;
|
||||
var util = require('util');
|
||||
var assert = require('assert');
|
||||
var deprecated = require('depd')('loopback-datasource-juggler');
|
||||
var DefaultModelBaseClass = require('./model.js');
|
||||
var List = require('./list.js');
|
||||
var ModelDefinition = require('./model-definition.js');
|
||||
|
@ -182,7 +183,20 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
|
|||
events.setMaxListeners(32);
|
||||
for (var f in EventEmitter.prototype) {
|
||||
if (typeof EventEmitter.prototype[f] === 'function') {
|
||||
ModelClass[f] = EventEmitter.prototype[f].bind(events);
|
||||
if (f !== 'on') {
|
||||
ModelClass[f] = EventEmitter.prototype[f].bind(events);
|
||||
continue;
|
||||
}
|
||||
|
||||
// report deprecation warnings at the time Model.on() is called
|
||||
ModelClass.on = function(event) {
|
||||
if (['changed', 'deleted', 'deletedAll'].indexOf(event) !== -1) {
|
||||
deprecated(this.modelName + '\'s event "' + event + '" ' +
|
||||
'is deprecated, use Operation hooks instead. ' +
|
||||
'http://docs.strongloop.com/display/LB/Operation+hooks');
|
||||
}
|
||||
EventEmitter.prototype.on.apply(events, arguments);
|
||||
};
|
||||
}
|
||||
}
|
||||
hiddenProperty(ModelClass, 'modelName', className);
|
||||
|
|
Loading…
Reference in New Issue