From 6b2c437ac78b88d34726f18d841bf2319126cbfa Mon Sep 17 00:00:00 2001 From: Marshall Thompson Date: Thu, 25 Dec 2014 20:09:38 -0700 Subject: [PATCH 1/5] Fixing hook order of execution. --- lib/before.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/before.js b/lib/before.js index 0b4b082..fea72c5 100644 --- a/lib/before.js +++ b/lib/before.js @@ -59,15 +59,16 @@ module.exports = function(service) { result[name].push(fn); }); }); - + var self = this; _.each(mixin, function(hooks, method){ - _.each(hooks, function(hook){ + // Reverse loop so hooks execute in correct order. + for (var i = hooks.length - 1; i >= 0; i--) { var obj = {}; - obj[method] = hook; + obj[method] = hooks[i]; self.mixin(obj); - }); + }; }); return this; From edfd227f595033caa6e363920ee0906ae44c2d1e Mon Sep 17 00:00:00 2001 From: Marshall Thompson Date: Thu, 25 Dec 2014 20:19:03 -0700 Subject: [PATCH 2/5] Reverse hook order using _.eachRight() --- lib/before.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/before.js b/lib/before.js index fea72c5..4507244 100644 --- a/lib/before.js +++ b/lib/before.js @@ -64,11 +64,11 @@ module.exports = function(service) { _.each(mixin, function(hooks, method){ // Reverse loop so hooks execute in correct order. - for (var i = hooks.length - 1; i >= 0; i--) { + _.eachRight(hooks, function(hook){ var obj = {}; - obj[method] = hooks[i]; + obj[method] = hook; self.mixin(obj); - }; + }); }); return this; From e56073007a1c81ddabd371f2ecb82376b07bfe8d Mon Sep 17 00:00:00 2001 From: Marshall Thompson Date: Thu, 25 Dec 2014 21:13:05 -0700 Subject: [PATCH 3/5] Better check for id. --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 0cb99f7..aeff740 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -44,7 +44,7 @@ exports.hookObject = function(method, args) { exports.makeArguments = function(hookObject) { var result = []; - if(hookObject.id) { + if(typeof hookObject.id !== 'undefined') { result.push(hookObject.id); } From 68828eea679c295753a30bd4badec339fa451266 Mon Sep 17 00:00:00 2001 From: Marshall Thompson Date: Thu, 25 Dec 2014 22:05:11 -0700 Subject: [PATCH 4/5] _.arrayRight() in after hooks. --- lib/after.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/after.js b/lib/after.js index 179f247..135d5fe 100644 --- a/lib/after.js +++ b/lib/after.js @@ -15,14 +15,14 @@ module.exports = function(service) { // Don't mix in if it is not a service method if(app.methods.indexOf(name) === -1) { return; - } + } if (!_.isArray(hooks)){ hooks = [hooks]; } result[name] = []; - + _.each(hooks, function(hook){ var fn = function() { var self = this; @@ -78,7 +78,7 @@ module.exports = function(service) { var self = this; _.each(mixin, function(hooks, method){ - _.each(hooks, function(hook){ + _.eachRight(hooks, function(hook){ var obj = {}; obj[method] = hook; self.mixin(obj); From 528323012bd1aabdf46f7012ce64317fe1f3b300 Mon Sep 17 00:00:00 2001 From: Marshall Thompson Date: Fri, 26 Dec 2014 11:24:41 -0700 Subject: [PATCH 5/5] Revert "_.arrayRight() in after hooks." This reverts commit 68828eea679c295753a30bd4badec339fa451266. --- lib/after.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/after.js b/lib/after.js index 135d5fe..179f247 100644 --- a/lib/after.js +++ b/lib/after.js @@ -15,14 +15,14 @@ module.exports = function(service) { // Don't mix in if it is not a service method if(app.methods.indexOf(name) === -1) { return; - } + } if (!_.isArray(hooks)){ hooks = [hooks]; } result[name] = []; - + _.each(hooks, function(hook){ var fn = function() { var self = this; @@ -78,7 +78,7 @@ module.exports = function(service) { var self = this; _.each(mixin, function(hooks, method){ - _.eachRight(hooks, function(hook){ + _.each(hooks, function(hook){ var obj = {}; obj[method] = hook; self.mixin(obj);