Skip to content

Commit

Permalink
Merge pull request #12056 from rwjblue/event-dispatcher-stuffs
Browse files Browse the repository at this point in the history
[BUGFIX release] Ensure initializers can augment customEvents.
  • Loading branch information
rwjblue committed Aug 11, 2015
2 parents 5a94703 + addbd22 commit 0c95d49
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 15 deletions.
5 changes: 3 additions & 2 deletions packages/ember-application/lib/system/application-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ let ApplicationInstance = EmberObject.extend(RegistryProxy, ContainerProxy, {

var application = get(this, 'application');

set(this, 'customEvents', get(application, 'customEvents'));
set(this, 'rootElement', get(application, 'rootElement'));

// Create a per-instance registry that will use the application's registry
Expand Down Expand Up @@ -188,7 +187,9 @@ let ApplicationInstance = EmberObject.extend(RegistryProxy, ContainerProxy, {
*/
setupEventDispatcher() {
var dispatcher = this.lookup('event_dispatcher:main');
dispatcher.setup(this.customEvents, this.rootElement);
var applicationCustomEvents = get(this.application, 'customEvents');

dispatcher.setup(applicationCustomEvents, this.rootElement);

return dispatcher;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,22 @@ QUnit.test('properties (and aliases) are correctly assigned for accessing the co
strictEqual(appInstance.registry, appInstance.__registry__, '#registry alias should be assigned');
}
});

QUnit.test('customEvents added to the application before setupEventDispatcher', function(assert) {
assert.expect(1);

run(function() {
appInstance = ApplicationInstance.create({ application: app });
});

app.customEvents = {
awesome: 'sauce'
};

var eventDispatcher = appInstance.lookup('event_dispatcher:main');
eventDispatcher.setup = function(events) {
assert.equal(events.awesome, 'sauce');
};

appInstance.setupEventDispatcher();
});
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
import 'ember';
import Ember from 'ember-metal/core';
import isEnabled from 'ember-metal/features';

var App, container, router;
var compile = Ember.HTMLBars.compile;

QUnit.module('Application Lifecycle', {
setup() {
Ember.run(function() {
App = Ember.Application.create({
rootElement: '#qunit-fixture'
});
var ApplicationSubclass, App, container, router;

App.Router = App.Router.extend({
location: 'none'
});

App.deferReadiness();
function setupApp() {
Ember.run(function() {
App = ApplicationSubclass.create({
rootElement: '#qunit-fixture'
});

container = App.__container__;
App.Router = App.Router.extend({
location: 'none'
});

App.deferReadiness();

container = App.__container__;
});
}

QUnit.module('Application Lifecycle', {
setup() {
ApplicationSubclass = Ember.Application.extend();

setupApp();
},

teardown() {
router = null;
Ember.run(App, 'destroy');
Ember.TEMPLATES = {};
}
});

Expand Down Expand Up @@ -113,3 +123,46 @@ QUnit.test('Destroying the application resets the router before the container is
equal(Ember.controllerFor(container, 'home').get('selectedMenuItem'), null);
equal(Ember.controllerFor(container, 'application').get('selectedMenuItem'), null);
});

QUnit.test('initializers can augment an applications customEvents hash', function(assert) {
assert.expect(1);

Ember.run(App, 'destroy');

if (isEnabled('ember-registry-container-reform')) {
ApplicationSubclass.initializer({
name: 'customize-things',
initialize(application) {
application.customEvents = {
wowza: 'wowza'
};
}
});
} else {
ApplicationSubclass.initializer({
name: 'customize-things',
initialize(registry, application) {
application.customEvents = {
wowza: 'wowza'
};
}
});
}

setupApp();

App.FooBarComponent = Ember.Component.extend({
wowza() {
assert.ok(true, 'fired the event!');
}
});

Ember.TEMPLATES['application'] = compile(`{{foo-bar}}`);
Ember.TEMPLATES['components/foo-bar'] = compile(`<div id='wowza-thingy'></div>`);

Ember.run(App, 'advanceReadiness');

Ember.run(function() {
Ember.$('#wowza-thingy').trigger('wowza');
});
});

0 comments on commit 0c95d49

Please sign in to comment.