diff --git a/source/object-model/observers.md b/source/object-model/observers.md index 0ff5c5e01..b7b42a0eb 100644 --- a/source/object-model/observers.md +++ b/source/object-model/observers.md @@ -15,9 +15,9 @@ Person = Ember.Object.extend({ return firstName + ' ' + lastName; }), - fullNameChanged: function() { + fullNameChanged: Ember.observer(function() { // deal with the change - }.observes('fullName').on('init') + }).on('init') }); var person = Person.create({ @@ -40,12 +40,12 @@ is easy to introduce bugs where properties are not yet synchronized: ```javascript Person.reopen({ - lastNameChanged: function() { + lastNameChanged: Ember.observer('lastName', function() { // The observer depends on lastName and so does fullName. Because observers // are synchronous, when this function is called the value of fullName is // not updated yet so this will log the old value of fullName console.log(this.get('fullName')); - }.observes('lastName') + }) }); ``` @@ -54,9 +54,9 @@ times when observing multiple properties: ```javascript Person.reopen({ - partOfNameChanged: function() { + partOfNameChanged: Ember.observer('firstName', 'lastName', function() { // Because both firstName and lastName were set, this observer will fire twice. - }.observes('firstName', 'lastName') + }) }); person.set('firstName', 'John'); @@ -69,9 +69,9 @@ next run loop once all bindings are synchronized: ```javascript Person.reopen({ - partOfNameChanged: function() { + partOfNameChanged: Ember.observer('firstName', 'lastName', function() { Ember.run.once(this, 'processFullName'); - }.observes('firstName', 'lastName'), + }), processFullName: function() { // This will only fire once if you set two properties at the same time, and @@ -98,9 +98,9 @@ Person = Ember.Object.extend({ this.set('salutation', "Mr/Ms"); }, - salutationDidChange: function() { + salutationDidChange: Ember.observer('salutation', function() { // some side effect of salutation changing - }.observes('salutation').on('init') + }).on('init') }); ``` @@ -118,20 +118,6 @@ observe it so you can update the DOM once the property changes. If you need to observe a computed property but aren't currently retrieving it, just get it in your init method. - -### Without prototype extensions - -You can define inline observers by using the `Ember.observer` method if you -are using Ember without prototype extensions: - -```javascript -Person.reopen({ - fullNameChanged: Ember.observer('fullName', function() { - // deal with the change - }) -}); -``` - ### Outside of class definitions You can also add observers to an object outside of a class definition diff --git a/source/testing/unit-testing-basics.md b/source/testing/unit-testing-basics.md index 5f3b7bdea..a8df79d7f 100644 --- a/source/testing/unit-testing-basics.md +++ b/source/testing/unit-testing-basics.md @@ -114,9 +114,9 @@ Suppose we have an object that has a property and a method observing that proper export default Ember.Object.extend({ foo: 'bar', other: 'no', - doSomething: function(){ + doSomething: Ember.observer('foo', function(){ this.set('other', 'yes'); - }.observes('foo') + }) }); ```