Skip to content

Instantly share code, notes, and snippets.

@ysfzrn
Created October 2, 2017 06:48
Show Gist options
  • Save ysfzrn/2f4e942fcd7aee26ee64a9c7816c261e to your computer and use it in GitHub Desktop.
Save ysfzrn/2f4e942fcd7aee26ee64a9c7816c261e to your computer and use it in GitHub Desktop.
import mobx, { observable, action, computed } from "mobx";
class Store {
@observable todos=[];
@observable selectedStatus="all";
@action('adding todo item')
addTodo(todo){
this.todos.push({
id: this.todos[this.todos.length - 1].id +1,
status: false,
text: todo
})
}
@action('Selected status changed')
statusChange(status){
this.selectedStatus = status;
}
@computed get filterTodos() {
if(this.selectedStatus === 'all'){
return this.todos;
} else if( this.selectedStatus === 'done' ){
return this.todos.filter(
todo => todo.status === true);
} else if( this.selectedStatus === 'todo' ){
return this.todos.filter(
todo => todo.status === false);
}
}
}
const todoStore = new Store()
export default todoStore;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment