/// import { Cell, Default, derive, handler, NAME, recipe, str, UI, } from "commontools"; const updater = handler< { delta: number }, { counter: Cell; error: string } >( ({ delta }, state) => { if (state.error) { console.error("testing throwing an error! in updater"); throw new Error(state.error); } state.counter.set((state.counter.get() ?? 0) + (delta ?? 1)); }, ); const updateError = handler< { detail: { value: string } }, { error: Cell } >( ({ detail }, state) => { state.error.set(detail?.value ?? ""); }, ); export default recipe< { error: Cell>; counter: Cell> } >( "bgCounter", ({ counter, error }) => { derive(counter, (counter) => { console.log("counter#", counter); }); return { [NAME]: str`Counter: ${derive(counter, (counter) => counter)}`, [UI]: ( Update Counter If error is set, the update function will throw an error {counter} ), bgUpdater: updater({ counter, error }), counter, }; }, );
If error is set, the update function will throw an error