Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE HTML>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mobx/3.2.2/mobx.umd.js"></script>
</body>
 
const {observable, observe, autorun, action} = mobx;
class TodoStore {
  @observable todos = [];
  constructor() {
    autorun(() => {
      const newTodos = this.todos.slice();
      
      console.log('The todos array was sent to firebase');
    })
  }
  @action addTodo(todo, important) {
    const newTodo = {
     id : Math.random(), 
     text : todo,
     isImportant : important,
     completed : false,
     date : Date.now()
    };
    this.todos.push(newTodo);
  }
}
const todoStore = new TodoStore();
setTimeout(() => {
  todoStore.addTodo('A todo', true);
  
  setTimeout(() => todoStore.todos[0].text = 'A changed todo', 1000);
}, 1000);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers