Skip to content

Commit

Permalink
feat(plugin): item prop for model:put put:called
Browse files Browse the repository at this point in the history
Added item prop to event object passed to model:put put:called listener.
  • Loading branch information
dolsem committed May 28, 2019
1 parent cf1f57a commit 5043cf3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/Model.js
Expand Up @@ -433,7 +433,7 @@ Model.prototype.put = async function (options, next) {
debug('put', this);
const deferred = Q.defer();
const emitObjectPutCalled = {
'event': {'callback': next, options},
'event': {'callback': next, options, 'item': this},
'actions': {
'updateCallback' (cb) { next = cb; },
'updateOptions' (newOptions) { options = newOptions; }
Expand Down
16 changes: 8 additions & 8 deletions test/Plugin.js
Expand Up @@ -576,20 +576,20 @@ describe('Plugin', function () {

Model.plugin(pluginA);

const myItem = new Model(
{
'id': 1,
'name': 'Lucky',
'owner': 'Bob',
'age': 2
}
);
const data = {
'id': 1,
'name': 'Lucky',
'owner': 'Bob',
'age': 2
};
const myItem = new Model(data);
myItem.save({'prop': true}, () => {
should.exist(emitObject);
emitObject.should.have.keys('model', 'modelName', 'plugins', 'plugin', 'event', 'actions');

emitObject.should.have.propertyByPath('event', 'type').which.is.eql('model:put');
emitObject.should.have.propertyByPath('event', 'stage').which.is.eql('put:called');
emitObject.should.have.propertyByPath('event', 'item').match(data);
emitObject.should.have.propertyByPath('event', 'options').match({'prop': true});
emitObject.should.have.propertyByPath('event', 'callback').which.is.Function;

Expand Down

0 comments on commit 5043cf3

Please sign in to comment.