///
import { Cell, handler, ifElse, recipe, UI } from "commontools";
interface Item {
id: number;
name: string;
}
// Handler that closes over both items array and individual item
const removeItem = handler<
unknown,
{ items: Cell>>; item: Cell- }
>((_event, { items, item }) => {
const currentItems = items.get();
const index = currentItems.findIndex((el) => el.equals(item));
if (index >= 0) {
items.set(currentItems.toSpliced(index, 1));
}
});
export default recipe<{ items: Item[]; hasItems: boolean }>(
"CT-1035: Map with handler inside ifElse",
({ items, hasItems }) => {
// CT-1035: Map inside ifElse branches should transform to mapWithPattern
// The handler closure should work correctly with the map iterator variable
return {
[UI]: (
{ifElse(
hasItems,
{items.map((item) => (
{item.name}
))}
,
No items
)}
),
};
},
);