minor tweak to plugins (used object format instead of potentially

confusing array)
v1.18.x
Julian Lam 12 years ago
parent 338acb8fc2
commit 1e39ae2f1e

@ -43,7 +43,7 @@ var fs = require('fs'),
Object.keys(_self.loadedHooks).forEach(function(hook) { Object.keys(_self.loadedHooks).forEach(function(hook) {
var hooks = _self.loadedHooks[hook]; var hooks = _self.loadedHooks[hook];
hooks = hooks.sort(function(a, b) { hooks = hooks.sort(function(a, b) {
return a[3] - b[3]; return a.priority - b.priority;
}); });
}); });
@ -140,7 +140,13 @@ var fs = require('fs'),
if (!data.priority) data.priority = 10; if (!data.priority) data.priority = 10;
_self.loadedHooks[data.hook] = _self.loadedHooks[data.hook] || []; _self.loadedHooks[data.hook] = _self.loadedHooks[data.hook] || [];
_self.loadedHooks[data.hook].push([id, data.method, !! data.callbacked, data.priority]); _self.loadedHooks[data.hook].push({
// [id, data.method, !! data.callbacked, data.priority]
id: id,
method: data.method,
callbacked: data.callbacked,
priority: data.priority
});
if (global.env === 'development') winston.info('[plugins] Hook registered: ' + data.hook + ' will call ' + id); if (global.env === 'development') winston.info('[plugins] Hook registered: ' + data.hook + ' will call ' + id);
callback(); callback();
@ -156,10 +162,10 @@ var fs = require('fs'),
switch (hookType) { switch (hookType) {
case 'filter': case 'filter':
async.reduce(hookList, args, function(value, hookObj, next) { async.reduce(hookList, args, function(value, hookObj, next) {
if (hookObj[2]) { // If a callback is present (asynchronous method) if (hookObj.callbacked) { // If a callback is present (asynchronous method)
_self.libraries[hookObj[0]][hookObj[1]](value, next); _self.libraries[hookObj.id][hookObj.method](value, next);
} else { // Synchronous method } else { // Synchronous method
value = _self.libraries[hookObj[0]][hookObj[1]](value); value = _self.libraries[hookObj.id][hookObj.method](value);
next(null, value); next(null, value);
} }
}, function(err, value) { }, function(err, value) {
@ -175,13 +181,13 @@ var fs = require('fs'),
case 'action': case 'action':
async.each(hookList, function(hookObj) { async.each(hookList, function(hookObj) {
if ( if (
_self.libraries[hookObj[0]] && _self.libraries[hookObj.id] &&
_self.libraries[hookObj[0]][hookObj[1]] && _self.libraries[hookObj.id][hookObj.method] &&
typeof _self.libraries[hookObj[0]][hookObj[1]] === 'function' typeof _self.libraries[hookObj.id][hookObj.method] === 'function'
) { ) {
_self.libraries[hookObj[0]][hookObj[1]].apply(_self.libraries[hookObj[0]], args); _self.libraries[hookObj.id][hookObj.method].apply(_self.libraries[hookObj.id], args);
} else { } else {
if (global.env === 'development') winston.info('[plugins] Expected method \'' + hookObj[1] + '\' in plugin \'' + hookObj[0] + '\' not found, skipping.'); if (global.env === 'development') winston.info('[plugins] Expected method \'' + hookObj.method + '\' in plugin \'' + hookObj.id + '\' not found, skipping.');
} }
}); });
break; break;

Loading…
Cancel
Save