From 0b83ff8ec286087aa9ee9f826d31d289be89e03a Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 31 Jan 2021 16:30:55 -0500 Subject: [PATCH] hooks: Simplify `syncMapFirst` iteration --- src/static/js/pluginfw/hooks.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/static/js/pluginfw/hooks.js b/src/static/js/pluginfw/hooks.js index 5e8d9e73b..98b2af4c8 100644 --- a/src/static/js/pluginfw/hooks.js +++ b/src/static/js/pluginfw/hooks.js @@ -39,12 +39,11 @@ const hookCallWrapper = (hook, hookName, context, cb) => { return () => normalize(hook.hook_fn(hookName, context, (x) => cb(normalize(x)))); }; -const syncMapFirst = (lst, fn) => { - let i; - let result; - for (i = 0; i < lst.length; i++) { - result = fn(lst[i]); - if (result.length) return result; +const syncMapFirst = (hooks, fn) => { + const predicate = (val) => val.length; + for (const hook of hooks) { + const val = fn(hook); + if (predicate(val)) return val; } return []; };