Skip to content

Commit 1d0685f

Browse files
committed
add conditional
1 parent 6d4514f commit 1d0685f

File tree

1 file changed

+5
-1
lines changed
  • typescript/packages/lookslike-high-level/src/recipes

1 file changed

+5
-1
lines changed

typescript/packages/lookslike-high-level/src/recipes/counters.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ const updateRandomItem = handler<
99
{},
1010
{ items: { title: string; count: number }[] }
1111
>(({}, state) => {
12-
state.items[Math.floor(Math.random() * state.items.length)].count += 1;
12+
// TODO(ja): if a handler throws an exception recipes
13+
// seems to stop updating / future handlers are not called.
14+
if (state.items.length > 0) {
15+
state.items[Math.floor(Math.random() * state.items.length)].count += 1;
16+
}
1317
});
1418

1519
const addItem = handler<{}, { items: { title: string; count: number }[] }>(

0 commit comments

Comments
 (0)