mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
using reduce to run filter hooks instead of eachSeries, and fixed up
incorrect usage of .apply() in tests folder
This commit is contained in:
@@ -155,26 +155,21 @@ var fs = require('fs'),
|
|||||||
var hookType = hook.split(':')[0];
|
var hookType = hook.split(':')[0];
|
||||||
switch (hookType) {
|
switch (hookType) {
|
||||||
case 'filter':
|
case 'filter':
|
||||||
var returnVal = args;
|
async.reduce(hookList, args, function(value, hookObj, next) {
|
||||||
|
if (hookObj[2]) { // If a callback is present (asynchronous method)
|
||||||
async.eachSeries(hookList, function(hookObj, next) {
|
_self.libraries[hookObj[0]][hookObj[1]](value, next);
|
||||||
if (hookObj[2]) {
|
} else { // Synchronous method
|
||||||
_self.libraries[hookObj[0]][hookObj[1]](returnVal, function(err, afterVal) {
|
value = _self.libraries[hookObj[0]][hookObj[1]](value);
|
||||||
returnVal = afterVal;
|
next(null, value);
|
||||||
next(err);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
returnVal = _self.libraries[hookObj[0]][hookObj[1]](returnVal);
|
|
||||||
next();
|
|
||||||
}
|
}
|
||||||
}, function(err) {
|
}, function(err, value) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (global.env === 'development') {
|
if (global.env === 'development') {
|
||||||
winston.info('[plugins] Problem executing hook: ' + hook);
|
winston.info('[plugins] Problem executing hook: ' + hook);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(err, returnVal);
|
callback.apply(plugins, arguments);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'action':
|
case 'action':
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ describe('Categories', function() {
|
|||||||
order: '5'
|
order: '5'
|
||||||
}, function(err, category) {
|
}, function(err, category) {
|
||||||
categoryObj = category;
|
categoryObj = category;
|
||||||
done.apply(arguments);
|
done.apply(this, arguments);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user