Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] Ensure initializers can augment customEvents. #12056

Merged
merged 1 commit into from
Aug 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});