Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created February 9, 2014 20:28
Show Gist options
  • Save Raynos/8905503 to your computer and use it in GitHub Desktop.
Save Raynos/8905503 to your computer and use it in GitHub Desktop.
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