Created
August 4, 2016 21:46
-
-
Save mbohgard/1dc66bb7f5fa66d2ed31cb320fcbc7e5 to your computer and use it in GitHub Desktop.
MobX implementation
This file contains 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
// todoStore.js | |
class TodoStore { | |
@observable todos = [] | |
getTodos = () => { | |
return this.todos | |
} | |
getTodo = id => { | |
return this.todos.find(todo => todo.id === id) | |
} | |
addTodo = text => { | |
this.todos.push({ id: Date.now(), text }) | |
} | |
removeTodo = id => { | |
this.todos = this.todos.filter(todo => todo.id !== id) | |
} | |
} | |
const todoStore = new TodoStore() | |
export default todoStore | |
// then in my components I import todoStore and call it's methods | |
// (instead passing it around through props, I just import it directly) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment