From 45f5865e87b5246ea0305a8db9ed1d8eb3c2be11 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Fri, 27 Mar 2015 09:10:03 -0700 Subject: [PATCH] some misc formatting cleanup --- .../adding_google_analytics_tracking.md | 4 +-- ...ing_a_textfield_after_its_been_inserted.md | 4 +-- .../continuous_redrawing_of_views.md | 31 ++++++++++--------- source/object-model/observers.md | 20 ++++++++---- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/source/cookbook/helpers_and_components/adding_google_analytics_tracking.md b/source/cookbook/helpers_and_components/adding_google_analytics_tracking.md index 5e489a6b4..3988697ee 100644 --- a/source/cookbook/helpers_and_components/adding_google_analytics_tracking.md +++ b/source/cookbook/helpers_and_components/adding_google_analytics_tracking.md @@ -40,12 +40,12 @@ var Router = Ember.Router.extend({ }); Router.reopen({ - notifyGoogleAnalytics: function() { + notifyGoogleAnalytics: Ember.on('didTransition', function() { return ga('send', 'pageview', { 'page': this.get('url'), 'title': this.get('url') }); - }.on('didTransition') + }) }); export default Router; diff --git a/source/cookbook/user_interface_and_interaction/focusing_a_textfield_after_its_been_inserted.md b/source/cookbook/user_interface_and_interaction/focusing_a_textfield_after_its_been_inserted.md index ba8ec18c6..47655ead2 100644 --- a/source/cookbook/user_interface_and_interaction/focusing_a_textfield_after_its_been_inserted.md +++ b/source/cookbook/user_interface_and_interaction/focusing_a_textfield_after_its_been_inserted.md @@ -8,9 +8,9 @@ to the text field by accessing the components's jQuery `$` property: ```app/components/focus-input.js export default Ember.TextField.extend({ - becomeFocused: function() { + becomeFocused: Ember.on('didInsertElement', function() { this.$().focus(); - }.on('didInsertElement') + }) }); ``` diff --git a/source/cookbook/working_with_objects/continuous_redrawing_of_views.md b/source/cookbook/working_with_objects/continuous_redrawing_of_views.md index 34e674387..84b15814a 100644 --- a/source/cookbook/working_with_objects/continuous_redrawing_of_views.md +++ b/source/cookbook/working_with_objects/continuous_redrawing_of_views.md @@ -27,6 +27,9 @@ of the interval. Since the `tick` method observes the incremented property another interval is triggered each time the property increases. ```app/services/clock.js +var observer = Ember.observer; +var on = Ember.on; + export default Ember.Object.extend({ init: function() { this._super.apply(this, arguments); @@ -34,7 +37,7 @@ export default Ember.Object.extend({ }, pulse: Ember.computed.oneWay('_seconds').readOnly(), - tick: Ember.observer('_seconds', function () { + tick: on(observer('_seconds', function () { var clock = this; Ember.run.later(function () { var seconds = clock.get('_seconds'); @@ -42,7 +45,7 @@ export default Ember.Object.extend({ clock.set('_seconds', seconds + (1/4)); } }, 250); - }).on('init') + }), 'init') }); ``` @@ -96,7 +99,7 @@ comment was created. ```app/controllers/comment-item.js export default Ember.ObjectController.extend({ - seconds: Ember.computed.oneWay('clock.pulse').readOnly() + seconds: Ember.computed.oneWay('clock.pulse').readOnly() }); ``` @@ -104,18 +107,18 @@ export default Ember.ObjectController.extend({ import ClockService from '../services/clock'; export default Ember.ArrayController.extend({ - itemController: 'commentItem', - comment: null, - actions: { - add: function () { - this.addObject(Em.Object.create({ - comment: this.get('comment'), - clock: ClockService.create() - })); - this.set('comment', null); - } + itemController: 'commentItem', + comment: null, + actions: { + add: function () { + this.addObject(Em.Object.create({ + comment: this.get('comment'), + clock: ClockService.create() + })); + this.set('comment', null); } - }); + } +}); ``` ### Handlebars template which displays the `pulse` diff --git a/source/object-model/observers.md b/source/object-model/observers.md index b7b42a0eb..ca2bce3d4 100644 --- a/source/object-model/observers.md +++ b/source/object-model/observers.md @@ -3,21 +3,25 @@ You can set up an observer on an object by using the `observes` method on a function: ```javascript +var computed = Ember.computed; +var observer = Ember.observer; +var on = Ember.on; + Person = Ember.Object.extend({ // these will be supplied by `create` firstName: null, lastName: null, - fullName: Ember.computed('firstName', 'lastName', function() { + fullName: computed('firstName', 'lastName', function() { var firstName = this.get('firstName'); var lastName = this.get('lastName'); return firstName + ' ' + lastName; }), - fullNameChanged: Ember.observer(function() { + fullNameChanged: on('init', observer('fullName', function() { // deal with the change - }).on('init') + })) }); var person = Person.create({ @@ -90,17 +94,21 @@ Observers never fire until after the initialization of an object is complete. If you need an observer to fire as part of the initialization process, you cannot rely on the side effect of set. Instead, specify that the observer -should also run after init by using `.on('init')`: +should also run after init by using `Ember.on('init')`: ```javascript +var observer = Ember.observer; +var on = Ember.on; + Person = Ember.Object.extend({ init: function() { + this._super.apply(this, arguments); this.set('salutation', "Mr/Ms"); }, - salutationDidChange: Ember.observer('salutation', function() { + salutationDidChange: on('init', observer('salutation', function() { // some side effect of salutation changing - }).on('init') + })) }); ```