From 5043cf3d11f2388a9fc2fa7b4b2d0e982a69b0c2 Mon Sep 17 00:00:00 2001 From: Denis Semenenko Date: Thu, 9 May 2019 14:10:16 -0400 Subject: [PATCH] feat(plugin): item prop for model:put put:called Added item prop to event object passed to model:put put:called listener. --- lib/Model.js | 2 +- test/Plugin.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Model.js b/lib/Model.js index 0fed5619e..057bb1d1b 100644 --- a/lib/Model.js +++ b/lib/Model.js @@ -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; } diff --git a/test/Plugin.js b/test/Plugin.js index 1b2f8a32c..a186ff3df 100644 --- a/test/Plugin.js +++ b/test/Plugin.js @@ -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;