Created
February 29, 2012 19:40
-
-
Save krisselden/1943884 to your computer and use it in GitHub Desktop.
Binding in prototype
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
testBoth("bindings should do the right thing when binding is in prototype", function(get, set) { | |
var obj, proto, a, b, selectionChanged; | |
Ember.run(function() { | |
obj = { | |
selection: null | |
}; | |
selectionChanged = 0; | |
Ember.addObserver(obj, 'selection', function () { | |
selectionChanged++; | |
}); | |
proto = { | |
obj: obj, | |
changeSelection: function (value) { | |
set(this, 'selection', value); | |
} | |
}; | |
Em.bind(proto, 'selection', 'obj.selection'); | |
a = Em.create(proto); | |
b = Em.create(proto); | |
}); | |
Em.run(function () { | |
set(a, 'selection', 'a'); | |
}); | |
Em.run(function () { | |
set(b, 'selection', 'b'); | |
}); | |
Em.run(function () { | |
set(a, 'selection', 'a'); | |
}); | |
equal(selectionChanged, 3); | |
equal(get(obj, 'selection'), 'a'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment