Created
February 9, 2014 20:28
-
-
Save Raynos/8905503 to your computer and use it in GitHub Desktop.
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
var counter = 0; | |
var ticks = 0; | |
setImmediate(function countTick() { | |
ticks++ | |
setImmediate(countTick) | |
}) | |
var todo = new ImObject({ | |
title: "foo", | |
completed: false | |
}, function onChange(todo2) { | |
counter++ | |
assert.equal(counter, 1) | |
assert.equal(ticks, 1) | |
assert.equal(todo2.title, "bar") | |
assert.equal(todo2.completed, true) | |
// if someone mutates todo2 then | |
// this onChange listener gets called | |
// with todo3 on the next setImmediate | |
// all mutations to todo2 are batched in | |
// it's tick and emit a new immutable todo3 | |
// in the next tick | |
}) | |
todo.title = "bar" | |
todo.completed = true | |
assert.equal(todo.title, "foo") | |
assert.equal(todo.completed, false) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment