Skip to content

Instantly share code, notes, and snippets.

@eihigh
Last active January 3, 2020 03:38
Show Gist options
  • Save eihigh/91b01a5a6443e04ffca2813a2ff772e4 to your computer and use it in GitHub Desktop.
Save eihigh/91b01a5a6443e04ffca2813a2ff772e4 to your computer and use it in GitHub Desktop.
// counterデモをgoban式で実現
const Counter = {
view: () => [
m("button", { onclick: aco.send(vm.x + 1, "msg") }, `val: ${vm.x}`),
m("button", { onclick: aco.send({}, "reset") }, "reset"),
m(Todos)
]
} as m.Component;
const Todos = {
view: () => vm.todos.map(todo => Todo(todo))
} as m.Component;
interface TodoAttr {
todo: string;
}
const Todo = (name: string): m.Children => {
return m("p", name);
};
class VM {
x: number = 42;
todos: string[] = [];
}
const vm = new VM();
const ctrl = async () => {
resetter();
pusher();
};
const resetter = async () => {
for (;;) {
await aco.recv("reset");
vm.todos = [];
}
};
const pusher = async () => {
for (;;) {
await aco.recv("msg");
vm.todos.push("hello");
}
};
ctrl();
m.mount(document.body, Counter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment