Skip to content

Instantly share code, notes, and snippets.

@ppcano
Created April 21, 2013 11:26
Show Gist options
  • Select an option

  • Save ppcano/5429299 to your computer and use it in GitHub Desktop.

Select an option

Save ppcano/5429299 to your computer and use it in GitHub Desktop.
example: Bindings/CP/observers
var bar, Bar;
module('Ember.Object compare Binding/CP/Observers', {
setup: function() {
},
teardown: function() {
if ( bar ) {
Ember.run(function(){
bar.destroy();
});
}
}
});
test('Observers are fired sync', function() {
var counter = 0;
Bar = Ember.Object.extend({
value: null,
valueDidChange: Ember.observer(function() {
counter++;
}, 'value')
});
bar = Bar.create({});
bar.set('value', true);
equal(counter, 1, 'observers are fired synchronously');
});
test('CP are sync', function() {
Bar = Ember.Object.extend({
value: true,
computedValue: Ember.computed(function(){
return !this.get('value');
}).property('value')
});
bar = Bar.create({});
bar.set('value', true);
equal(bar.get('computedValue') , false, 'CP are fired synchronously');
});
test('Bindings are async', function() {
Bar = Ember.Object.extend({
value: true,
computedValueBinding: 'value'
});
bar = Bar.create({});
Ember.run(function(){
bar.set('value', false);
equal(bar.get('computedValue') , true, 'Bindings are not updated after next `sync` queue');
});
equal(bar.get('computedValue') , false, 'Bindings are fired synchronously');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment