diff --git a/src/mixins/event.js b/src/mixins/event.js index 066e14a5e4..3dede8e681 100644 --- a/src/mixins/event.js +++ b/src/mixins/event.js @@ -15,6 +15,7 @@ function upperCase(name) { } export default function(service) { + const app = this; const isEmitter = typeof service.on === 'function' && typeof service.emit === 'function'; const emitter = service._rubberDuck = rubberduck.emitter(service); @@ -47,6 +48,7 @@ export default function(service) { const hook = hookObject(method, 'after', args); const data = Array.isArray(results[1]) ? results[1] : [ results[1] ]; + hook.app = app; data.forEach(current => service.emit(event, current, hook)); } else { service.emit('serviceError', results[0]); diff --git a/test/mixins/event.test.js b/test/mixins/event.test.js index be80cb76c9..d26b50b0e1 100644 --- a/test/mixins/event.test.js +++ b/test/mixins/event.test.js @@ -209,4 +209,29 @@ describe('Event mixin', () => { instance.emit('created', { custom: 'event' }); }); }); + + it('sets hook.app', done => { + const FixtureService = Proto.extend({ + update(id, data, params, cb) { + setTimeout(function () { + cb(null, { + id: id, + name: data.name + }); + }, 20); + } + }); + + const instance = create.call(FixtureService); + const dummyApp = { isApp: true }; + + mixinEvent.call(dummyApp, instance); + + instance.on('updated', function (data, hook) { + assert.deepEqual(hook.app, dummyApp); + done(); + }); + + instance.update(12, { name: 'Updated tester' }, {}, function () {}); + }); });