Created
October 2, 2017 06:48
-
-
Save ysfzrn/2f4e942fcd7aee26ee64a9c7816c261e 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
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