///
import { Cell, Default, handler, lift, recipe } from "commontools";
interface LiftFormattingArgs {
value: Default;
}
const addOne = handler(
(
event: { amount?: number } | undefined,
context: { value: Cell },
) => {
const amount = typeof event?.amount === "number" ? event.amount : 1;
const next = (context.value.get() ?? 0) + amount;
context.value.set(next);
},
);
export const counterWithLiftFormatting = recipe(
"Counter With Lift Formatting",
({ value }) => {
const formatted = lift((count: number) => `Value: ${count.toFixed(2)}`)(
value,
);
return {
value,
formatted,
increment: addOne({ value }),
};
},
);