Skip to content

Commit

Permalink
Fix issue with all object handler hooks being global
Browse files Browse the repository at this point in the history
  • Loading branch information
lteacher committed Mar 18, 2020
1 parent 6428640 commit 8e51fb9
Show file tree
Hide file tree
Showing 4 changed files with 2,399 additions and 38 deletions.
15 changes: 2 additions & 13 deletions lib/handler-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,12 @@ class HandlerFactory {
* A handler is just a regular function but it can return a promise
*/
register(handlers, hooks) {
let isGlobal = true;
let useKey = false;

if (_.isPlainObject(handlers)) {
useKey = true;
} else if (!_.isArray(handlers)) {
handlers = [handlers];
isGlobal = false;
}

_.forEach(handlers, (handler, key) => {
Expand All @@ -138,19 +136,10 @@ class HandlerFactory {
this.registerByName(name, handler);

// Setup the hooks for the handler if any
if (!isGlobal) {
if (hooks) {
_.forEach(_.keys(hooks), (order) => this[order](handler, hooks[order]));
}
}
});

// Setup the hooks for the global if any
if (isGlobal) {
if (hooks) {
_.forEach(_.keys(hooks), (order) => this[order]('*', hooks[order]));
_.forEach(_.keys(hooks), (order) => this[order](handler, hooks[order]));
}
}
});
}

registerByName(name, handler) {
Expand Down

0 comments on commit 8e51fb9

Please sign in to comment.