Skip to content

Commit

Permalink
[BUGFIX release] Ensure that multiple app event dispatching works pro…
Browse files Browse the repository at this point in the history
…perly.
  • Loading branch information
rwjblue committed May 27, 2015
1 parent a0acc6e commit 875f9bb
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export function createComponent(_component, isAngleBracket, _props, renderNode,
}

props.renderer = props.parentView ? props.parentView.renderer : env.container.lookup('renderer:-dom');
props._viewRegistry = props.parentView ? props.parentView._viewRegistry : props.container && props.container.lookup('-view-registry:main');
props._viewRegistry = props.parentView ? props.parentView._viewRegistry : env.container.lookup('-view-registry:main');

let component = _component.create(props);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ var ViewChildViewsSupport = Mixin.create({
var attrs = _attrs || {};
var view;
attrs.renderer = this.renderer;
attrs._viewRegistry = this._viewRegistry;

if (maybeViewClass.isViewFactory) {
attrs.container = this.container;
Expand Down
6 changes: 2 additions & 4 deletions packages/ember-views/lib/system/event_dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import ActionManager from "ember-views/system/action_manager";
import View from "ember-views/views/view";
import merge from "ember-metal/merge";

//ES6TODO:
// find a better way to do Ember.View.views without global state

/**
`Ember.EventDispatcher` handles delegating browser events to their
corresponding `Ember.Views.` For example, when you click on a view,
Expand Down Expand Up @@ -174,7 +171,8 @@ export default EmberObject.extend({
var self = this;

rootElement.on(event + '.ember', '.ember-view', function(evt, triggeringManager) {
var view = View.views[this.id];
var viewRegistry = self.container && self.container.lookup('-view-registry:main') || View.views;
var view = viewRegistry[this.id];
var result = true;

var manager = self.canDispatchToEventManager ? self._findNearestEventManager(view, eventName) : null;
Expand Down
67 changes: 67 additions & 0 deletions packages/ember/tests/integration/multiple-app-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import compile from "ember-template-compiler/system/compile";
import run from "ember-metal/run_loop";

var App1, App2, actions;

function startApp(rootElement) {
var application;

run(function() {
application = Ember.Application.create({
rootElement
});
application.deferReadiness();

application.Router.reopen({
location: 'none'
});

var registry = application.__container__._registry;

registry.register('component:special-button', Ember.Component.extend({
actions: {
doStuff: function() {
actions.push(rootElement);
}
}
}));
registry.register('template:application', compile("{{outlet}}", { moduleName: 'application' }));
registry.register('template:index', compile("<h1>Node 1</h1>{{special-button}}", { moduleName: 'index' }));
registry.register('template:components/special-button', compile("<button class='do-stuff' {{action 'doStuff'}}>Button</button>", { moduleName: 'components/special-button' }));
});

return application;
}

function handleURL(application, path) {
var router = application.__container__.lookup('router:main');
return run(router, 'handleURL', path);
}

QUnit.module("View Integration", {
setup() {
actions = [];
Ember.$('#qunit-fixture').html('<div id="app-1"></div><div id="app-2"></div>');
App1 = startApp('#app-1');
App2 = startApp('#app-2');
},

teardown() {
run(App1, 'destroy');
run(App2, 'destroy');
App1 = App2 = null;
}
});

QUnit.test("booting multiple applications can properly handle events", function(assert) {
run(App1, 'advanceReadiness');
run(App2, 'advanceReadiness');

handleURL(App1, '/');
handleURL(App2, '/');

Ember.$('#app-2 .do-stuff').click();
Ember.$('#app-1 .do-stuff').click();

assert.deepEqual(actions, ['#app-2', '#app-1']);
});

0 comments on commit 875f9bb

Please sign in to comment.