From 875f9bbcf8449cd8db8a6cf8bf5cb1781a28c937 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Wed, 27 May 2015 10:58:46 -0400 Subject: [PATCH] [BUGFIX release] Ensure that multiple app event dispatching works properly. --- .../node-managers/component-node-manager.js | 2 +- .../lib/mixins/view_child_views_support.js | 1 + .../lib/system/event_dispatcher.js | 6 +- .../tests/integration/multiple-app-test.js | 67 +++++++++++++++++++ 4 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 packages/ember/tests/integration/multiple-app-test.js diff --git a/packages/ember-htmlbars/lib/node-managers/component-node-manager.js b/packages/ember-htmlbars/lib/node-managers/component-node-manager.js index 3c1d03b455e..cf3c0e2df5e 100644 --- a/packages/ember-htmlbars/lib/node-managers/component-node-manager.js +++ b/packages/ember-htmlbars/lib/node-managers/component-node-manager.js @@ -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); diff --git a/packages/ember-views/lib/mixins/view_child_views_support.js b/packages/ember-views/lib/mixins/view_child_views_support.js index 3acc930fffa..ace268e7412 100644 --- a/packages/ember-views/lib/mixins/view_child_views_support.js +++ b/packages/ember-views/lib/mixins/view_child_views_support.js @@ -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; diff --git a/packages/ember-views/lib/system/event_dispatcher.js b/packages/ember-views/lib/system/event_dispatcher.js index 17e7831196d..e0b902b67a1 100644 --- a/packages/ember-views/lib/system/event_dispatcher.js +++ b/packages/ember-views/lib/system/event_dispatcher.js @@ -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, @@ -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; diff --git a/packages/ember/tests/integration/multiple-app-test.js b/packages/ember/tests/integration/multiple-app-test.js new file mode 100644 index 00000000000..6d3b41166e0 --- /dev/null +++ b/packages/ember/tests/integration/multiple-app-test.js @@ -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("

Node 1

{{special-button}}", { moduleName: 'index' })); + registry.register('template:components/special-button', compile("", { 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('
'); + 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']); +});