Skip to content

Commit 23361fe

Browse files
committed
Remove reduce in Navigation state change
1 parent 439afe4 commit 23361fe

File tree

2 files changed

+21
-34
lines changed

2 files changed

+21
-34
lines changed

src/components/Navigation.mjs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -527,21 +527,20 @@ function Navigation(Props) {
527527
}), []);
528528
var fixedNav = fixed ? "fixed top-0" : "relative";
529529
var onStateChange = function (id, state) {
530-
Curry._1(setCollapsibles, (function (prev) {
531-
return prev.reduce((function (acc, next) {
532-
if (next.title === id) {
533-
acc.push({
534-
title: next.title,
535-
children: next.children,
536-
isActiveRoute: next.isActiveRoute,
537-
href: next.href,
538-
state: state
539-
});
540-
}
541-
return acc;
542-
}), []);
543-
}));
544-
530+
return Curry._1(setCollapsibles, (function (prev) {
531+
return Belt_Array.keepMap(prev, (function (next) {
532+
if (next.title === id) {
533+
return {
534+
title: next.title,
535+
children: next.children,
536+
isActiveRoute: next.isActiveRoute,
537+
href: next.href,
538+
state: state
539+
};
540+
}
541+
542+
}));
543+
}));
545544
};
546545
var collapsibleElements = collapsibles.map(function (coll) {
547546
return React.createElement(Navigation$CollapsibleLink, {

src/components/Navigation.res

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -493,26 +493,14 @@ let make = (~fixed=true, ~overlayState: (bool, (bool => bool) => unit)) => {
493493

494494
let onStateChange = (~id, state) => {
495495
setCollapsibles(prev => {
496-
Js.Array2.reduce(
497-
prev,
498-
(acc, next) => {
499-
if next.title === id {
500-
acc
501-
->Js.Array2.push({
502-
...next,
503-
state: state,
504-
})
505-
->ignore
506-
} else {
507-
()
508-
}
509-
510-
acc
511-
},
512-
[],
513-
)
496+
Belt.Array.keepMap(prev, next=> {
497+
if next.title === id {
498+
Some({...next, state: state})
499+
} else {
500+
None
501+
}
502+
})
514503
})
515-
()
516504
}
517505

518506
let collapsibleElements = Js.Array2.map(collapsibles, coll => {

0 commit comments

Comments
 (0)