viewof counter = {
const Msg = folktale.adt.union.union('Msg', {
Increment() {
return {};
},
Decrement(title) {
return { title };
}
});
function update(message, model) {
if (!message) return [model, cmd.none];
return message.matchWith({
Increment: () => [model + 1, cmd.none],
Decrement: () => [model - 1, cmd.none]
});
}
function view(model, dispatch) {
const bind = events.bind(Msg, dispatch);
return h('div', {}, [
h('button', { on: { click: bind(Msg.Increment) } }, '+'),
h('div', {}, model),
h('button', { on: { click: bind(Msg.Decrement) } }, '-')
]);
}
return app({
view,
update,
init: () => 0
});
}