Skip to content

Instantly share code, notes, and snippets.

@krisselden
Created February 29, 2012 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisselden/1943884 to your computer and use it in GitHub Desktop.
Save krisselden/1943884 to your computer and use it in GitHub Desktop.
Binding in prototype
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