Skip to content

Commit

Permalink
feat: Allow to skip sending service events (#1270)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Apr 3, 2019
1 parent 30da15a commit b487bbd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/feathers/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Proto = require('uberproto');
const eventHook = exports.eventHook = function eventHook () {
return function (hook) {
const { app, service } = hook;
const eventName = app.eventMappings[hook.method];
const eventName = hook.event === null ? hook.event : app.eventMappings[hook.method];
const isHookEvent = service._hookEvents && service._hookEvents.indexOf(eventName) !== -1;

// If this event is not being sent yet and we are not in an error hook
Expand Down
26 changes: 26 additions & 0 deletions packages/feathers/test/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ describe('Service events', () => {
service.create({ message: 'Hello' });
});

it('allows to skip event emitting', done => {
const app = feathers().use('/creator', {
create (data) {
return Promise.resolve(data);
}
});

const service = app.service('creator');

service.hooks({
before: {
create (context) {
context.event = null;

return context;
}
}
});

service.on('created', data => {
done(new Error('Should never get here'));
});

service.create({ message: 'Hello' }).then(() => done());
});

it('.update and updated', done => {
const app = feathers().use('/creator', {
update (id, data) {
Expand Down

0 comments on commit b487bbd

Please sign in to comment.