diff --git a/src/static/js/pluginfw/hooks.js b/src/static/js/pluginfw/hooks.js index 7f26c3bfb..489709e33 100644 --- a/src/static/js/pluginfw/hooks.js +++ b/src/static/js/pluginfw/hooks.js @@ -78,7 +78,7 @@ exports.callAll = function (hook_name, args) { } } -exports.aCallAll = function (hook_name, args, cb) { +function aCallAll(hook_name, args, cb) { if (!args) args = {}; if (!cb) cb = function () {}; if (exports.plugins.hooks[hook_name] === undefined) return cb(null, []); @@ -93,6 +93,19 @@ exports.aCallAll = function (hook_name, args, cb) { ); } +/* return a Promise if cb is not supplied */ +exports.aCallAll = function (hook_name, args, cb) { + if (cb === undefined) { + return new Promise(function(resolve, reject) { + aCallAll(hook_name, args, function(err, res) { + return err ? reject(err) : resolve(res); + }); + }); + } else { + return aCallAll(hook_name, args, cb); + } +} + exports.callFirst = function (hook_name, args) { if (!args) args = {}; if (exports.plugins.hooks[hook_name] === undefined) return []; @@ -101,7 +114,7 @@ exports.callFirst = function (hook_name, args) { }); } -exports.aCallFirst = function (hook_name, args, cb) { +function aCallFirst(hook_name, args, cb) { if (!args) args = {}; if (!cb) cb = function () {}; if (exports.plugins.hooks[hook_name] === undefined) return cb(null, []); @@ -114,6 +127,19 @@ exports.aCallFirst = function (hook_name, args, cb) { ); } +/* return a Promise if cb is not supplied */ +exports.aCallFirst = function (hook_name, args, cb) { + if (cb === undefined) { + return new Promise(function(resolve, reject) { + aCallFirst(hook_name, args, function(err, res) { + return err ? reject(err) : resolve(res); + }); + }); + } else { + return aCallFirst(hook_name, args, cb); + } +} + exports.callAllStr = function(hook_name, args, sep, pre, post) { if (sep == undefined) sep = ''; if (pre == undefined) pre = '';