Skip to content

Instantly share code, notes, and snippets.

@jitinics
Last active June 11, 2019 18:17
Show Gist options
  • Save jitinics/5654a455769c2046f91416a2f2e0d93b to your computer and use it in GitHub Desktop.
Save jitinics/5654a455769c2046f91416a2f2e0d93b to your computer and use it in GitHub Desktop.
class ObservableTodoStore {
@observable todos = [];
@observable pendingRequests = 0;
constructor() {
mobx.autorun(() => console.log(this.report));
}
@computed get completedTodosCount() {
return this.todos.filter(
todo => todo.completed === true
).length;
}
@computed get report() {
if (this.todos.length === 0)
return "<none>";
return `Next todo: "${this.todos[0].task}". ` +
`Progress: ${this.completedTodosCount}/${this.todos.length}`;
}
@action
addTodo(task) {
this.todos.push({
task: task,
completed: false,
assignee: null
});
}
}
const observableTodoStore = new ObservableTodoStore();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment