Last active
February 26, 2016 17:59
-
-
Save mweststrate/84fe2ba1c651a9a4bc2e to your computer and use it in GitHub Desktop.
Object.observe is dead. Long live Mobservable.observe
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
// 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