Slide 13
Slide 13 text
// @flow
import { autorun, observable, action, computed } from 'mobx';
type Task = {
task: string,
completed: boolean,
assignee: ?string,
}
export default class TodoStore {
@observable todos: Array = [];
@observable pendingRequests: number = 0;
constructor() {
autorun(() => console.log(this.report));
}
@computed get completedTodosCount(): number {
return this.todos.filter(todo => todo.completed === true).length;
}
@computed get report(): string {
if (this.todos.length === 0) {
return "";
} else {
return `Next todo: "${this.todos[0].task}". ` +
`Progress: ${this.completedTodosCount}/${this.todos.length}`;
}
}
@action addTodo(task: string): void {
this.todos.push({task, completed: false, assignee: null});
}
}
モジュール(export, import)
IUUQTCBCFMKTJPMFBSOFTFDNBTDSJQU
GFBUVSFTNPEVMFT