hooks: Rename `args` to `context` for consistency
parent
7dba847f21
commit
f02f288e80
|
@ -26,7 +26,7 @@ const checkDeprecation = (hook) => {
|
||||||
// Flattens the array one level.
|
// Flattens the array one level.
|
||||||
const flatten1 = (array) => array.reduce((a, b) => a.concat(b), []);
|
const flatten1 = (array) => array.reduce((a, b) => a.concat(b), []);
|
||||||
|
|
||||||
const hookCallWrapper = (hook, hookName, args, cb) => {
|
const hookCallWrapper = (hook, hookName, context, cb) => {
|
||||||
if (cb === undefined) cb = (x) => x;
|
if (cb === undefined) cb = (x) => x;
|
||||||
|
|
||||||
checkDeprecation(hook);
|
checkDeprecation(hook);
|
||||||
|
@ -36,7 +36,7 @@ const hookCallWrapper = (hook, hookName, args, cb) => {
|
||||||
if (x === undefined) return [];
|
if (x === undefined) return [];
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
return () => normalize(hook.hook_fn(hookName, args, (x) => cb(normalize(x))));
|
return () => normalize(hook.hook_fn(hookName, context, (x) => cb(normalize(x))));
|
||||||
};
|
};
|
||||||
|
|
||||||
const syncMapFirst = (lst, fn) => {
|
const syncMapFirst = (lst, fn) => {
|
||||||
|
@ -344,21 +344,21 @@ exports.aCallAll = async (hookName, context, cb) => {
|
||||||
return await resultsPromise;
|
return await resultsPromise;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.callFirst = (hookName, args) => {
|
exports.callFirst = (hookName, context) => {
|
||||||
if (!args) args = {};
|
if (!context) context = {};
|
||||||
if (pluginDefs.hooks[hookName] === undefined) return [];
|
if (pluginDefs.hooks[hookName] === undefined) return [];
|
||||||
return syncMapFirst(pluginDefs.hooks[hookName],
|
return syncMapFirst(pluginDefs.hooks[hookName],
|
||||||
(hook) => hookCallWrapper(hook, hookName, args));
|
(hook) => hookCallWrapper(hook, hookName, context));
|
||||||
};
|
};
|
||||||
|
|
||||||
const aCallFirst = (hookName, args, cb, predicate) => {
|
const aCallFirst = (hookName, context, cb, predicate) => {
|
||||||
if (!args) args = {};
|
if (!context) context = {};
|
||||||
if (!cb) cb = () => {};
|
if (!cb) cb = () => {};
|
||||||
if (pluginDefs.hooks[hookName] === undefined) return cb(null, []);
|
if (pluginDefs.hooks[hookName] === undefined) return cb(null, []);
|
||||||
mapFirst(
|
mapFirst(
|
||||||
pluginDefs.hooks[hookName],
|
pluginDefs.hooks[hookName],
|
||||||
(hook, cb) => {
|
(hook, cb) => {
|
||||||
hookCallWrapper(hook, hookName, args, (res) => { cb(null, res); });
|
hookCallWrapper(hook, hookName, context, (res) => { cb(null, res); });
|
||||||
},
|
},
|
||||||
cb,
|
cb,
|
||||||
predicate
|
predicate
|
||||||
|
@ -366,13 +366,13 @@ const aCallFirst = (hookName, args, cb, predicate) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* return a Promise if cb is not supplied */
|
/* return a Promise if cb is not supplied */
|
||||||
exports.aCallFirst = (hookName, args, cb, predicate) => {
|
exports.aCallFirst = (hookName, context, cb, predicate) => {
|
||||||
if (cb === undefined) {
|
if (cb === undefined) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
aCallFirst(hookName, args, (err, res) => err ? reject(err) : resolve(res), predicate);
|
aCallFirst(hookName, context, (err, res) => err ? reject(err) : resolve(res), predicate);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return aCallFirst(hookName, args, cb, predicate);
|
return aCallFirst(hookName, context, cb, predicate);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue