mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 00:16:15 -04:00
hooks: Simplify syncMapFirst
iteration
This commit is contained in:
parent
c89db33ff0
commit
0b83ff8ec2
1 changed files with 5 additions and 6 deletions
|
@ -39,12 +39,11 @@ const hookCallWrapper = (hook, hookName, context, cb) => {
|
||||||
return () => normalize(hook.hook_fn(hookName, context, (x) => cb(normalize(x))));
|
return () => normalize(hook.hook_fn(hookName, context, (x) => cb(normalize(x))));
|
||||||
};
|
};
|
||||||
|
|
||||||
const syncMapFirst = (lst, fn) => {
|
const syncMapFirst = (hooks, fn) => {
|
||||||
let i;
|
const predicate = (val) => val.length;
|
||||||
let result;
|
for (const hook of hooks) {
|
||||||
for (i = 0; i < lst.length; i++) {
|
const val = fn(hook);
|
||||||
result = fn(lst[i]);
|
if (predicate(val)) return val;
|
||||||
if (result.length) return result;
|
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue