Created
April 21, 2013 11:26
-
-
Save ppcano/5429299 to your computer and use it in GitHub Desktop.
example: Bindings/CP/observers
This file contains hidden or 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 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