Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEMVER-MAJOR] Remove model events #965

Merged
merged 1 commit into from
Jun 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions 3.0-RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,17 @@ silently ignored. This has been fixed in 3.0, therefore an undefined mixin
applied to a LoopBack model will throw an error that needs to be handled.

See [related code change](https://github.com/strongloop/loopback-datasource-juggler/pull/944)
for more details.

##Remove deprecated model hooks and model events

The following deprecated model events are now removed. Please upgrade your code by using
operation hooks in its place.

Model events
* changed
* deletedAll
* deleted

See [related code change](https://github.com/strongloop/loopback-datasource-juggler/pull/965)
for more details.
21 changes: 0 additions & 21 deletions lib/dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ DataAccessObject.create = function(data, options, cb) {

Model.notifyObserversOf('after save', context, function(err) {
cb(err, obj);
if (!err) Model.emit('changed', obj);
});
});
});
Expand Down Expand Up @@ -583,9 +582,6 @@ DataAccessObject.upsert = function(data, options, cb) {
}
if (err) {
cb(err, obj);
if (!err) {
Model.emit('changed', inst);
}
} else {
var context = {
Model: Model,
Expand All @@ -597,9 +593,6 @@ DataAccessObject.upsert = function(data, options, cb) {

Model.notifyObserversOf('after save', context, function(err) {
cb(err, obj);
if (!err) {
Model.emit('changed', inst);
}
});
}
});
Expand Down Expand Up @@ -778,8 +771,6 @@ DataAccessObject.replaceOrCreate = function replaceOrCreate(data, options, cb) {
};

Model.notifyObserversOf('after save', context, function(err) {
if (!err) Model.emit('changed', inst);

cb(err, obj, info);
});
}
Expand Down Expand Up @@ -904,7 +895,6 @@ DataAccessObject.findOrCreate = function findOrCreate(query, data, options, cb)
} else {
cb(err, obj, created);
}
if (!err) Model.emit('changed', obj);
});
} else {
if (cb.promise) {
Expand Down Expand Up @@ -1972,8 +1962,6 @@ DataAccessObject.destroyAll = function destroyAll(where, options, cb) {
};
Model.notifyObserversOf('after delete', context, function(err) {
cb(err, info);
if (!err)
Model.emit('deletedAll', whereIsEmpty(where) ? undefined : where);
});
}
}
Expand Down Expand Up @@ -2040,7 +2028,6 @@ DataAccessObject.deleteById = function deleteById(id, options, cb) {
}

cb(null, info);
Model.emit('deleted', id);
});
return cb.promise;
};
Expand Down Expand Up @@ -2248,9 +2235,6 @@ DataAccessObject.prototype.save = function(options, cb) {
updateDone.call(inst, function() {
saveDone.call(inst, function() {
cb(err, inst);
if (!err) {
Model.emit('changed', inst);
}
});
});
});
Expand Down Expand Up @@ -2514,7 +2498,6 @@ DataAccessObject.prototype.remove =
};
Model.notifyObserversOf('after delete', context, function(err) {
cb(err, info);
if (!err) Model.emit('deleted', id);
});
});
return;
Expand All @@ -2541,7 +2524,6 @@ DataAccessObject.prototype.remove =
};
Model.notifyObserversOf('after delete', context, function(err) {
cb(err, info);
if (!err) Model.emit('deleted', id);
});
});
}
Expand Down Expand Up @@ -2751,8 +2733,6 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
options: options,
};
Model.notifyObserversOf('after save', context, function(err) {
if (!err) Model.emit('changed', inst);

cb(err, inst);
});
});
Expand Down Expand Up @@ -2941,7 +2921,6 @@ function(data, options, cb) {
options: options,
};
Model.notifyObserversOf('after save', context, function(err) {
if (!err) Model.emit('changed', inst);
cb(err, inst);
});
});
Expand Down
15 changes: 1 addition & 14 deletions lib/model-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,7 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
events.setMaxListeners(32);
for (var f in EventEmitter.prototype) {
if (typeof EventEmitter.prototype[f] === 'function') {
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);
};
ModelClass[f] = EventEmitter.prototype[f].bind(events);
}
}
hiddenProperty(ModelClass, 'modelName', className);
Expand Down
1 change: 0 additions & 1 deletion lib/relation-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -2726,7 +2726,6 @@ EmbedsMany.prototype.destroyById = function(fkId, options, cb) {
if (err) return cb(err);
modelTo.notifyObserversOf('after delete', context, function(err) {
cb(err);
modelTo.emit('deleted', inst.id, inst.toJSON());
});
});
});
Expand Down
82 changes: 0 additions & 82 deletions test/events.js

This file was deleted.