emberjs/ember.js — pull request #3155 by lukemelia (2013-08-17 23:02:42+00:00)
Title: Add Ember.on, Function.prototype.on, and didInit event

This PR adds `Ember.on(eventName, func)` and `Function.prototype.on`
as cousins to `Ember.observes` and `Function.prototype.observes`. This
provides a declarative form of marking methods to execute when an event
fires.

This is useful for mixins which need to do things on `didInsertElement` and `willDestroyElement`, but don't want to force a call to `super` from the classes that include it:

Ember.Mixin.create({
doSomethingWithElement: function() {
// Executes whenever the "didInsertElement" event fires, regardless of the presence of a method named `didInsertElement`
}.on('didInsertElement')
});

In addition, this commit also makes Ember.Object send a `didInit` event after initializing. This provides for an elegant solution to a common need: marking a function as an observer and also executing it at creation time. e.g.

Ember.Object.extend({
upateOptions: function(){
var opts = this.get('controller.foo').importantTransform();
this.set('options', opts);
}.observes('controller.foo').on('didInit')
});