Last active
June 11, 2019 18:17
-
-
Save jitinics/5654a455769c2046f91416a2f2e0d93b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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