Skip to content

Instantly share code, notes, and snippets.

@mweststrate
Last active February 26, 2016 17:59
Show Gist options
  • Save mweststrate/84fe2ba1c651a9a4bc2e to your computer and use it in GitHub Desktop.
Save mweststrate/84fe2ba1c651a9a4bc2e to your computer and use it in GitHub Desktop.
Object.observe is dead. Long live Mobservable.observe
// JSBin: http://jsbin.com/xoyehi/edit?js,console
import {observable, autorun} from "mobx";
const todos = observable([{
title: "Find napkin",
completed: false
}]);
autorun(() =>
console.log(todos
.filter(todo => !todo.completed)
.map(todo => todo.title)
.join(", "))
);
// Prints: 'Find napkin'
todos[1] = {
title: "Sneeze",
completed: false
};
// Prints: 'Find napkin, Sneeze'
todos[0].completed = true;
// Prints: 'Sneeze'
todos[1].title = 'Ha.. ha... ha....'
// Prints: 'Ha.. ha... ha.... '
todos[0].title = "Foobar";
// (doesn't print)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment