From c0a8c98147c1377ab233f8c5f8957a94adb43066 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Thu, 12 Feb 2015 14:14:18 -0500 Subject: [PATCH] [BUGFIX beta] Fix top-level non-default outlet disconnection This resolves the secondary issue reported in [a comment](https://github.com/emberjs/ember.js/issues/10416#issuecomment-74112126) on issue #10416. --- packages/ember-routing/lib/system/route.js | 4 ++- packages/ember/tests/routing/basic_test.js | 32 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/ember-routing/lib/system/route.js b/packages/ember-routing/lib/system/route.js index f051c41514e..b891c29ceea 100644 --- a/packages/ember-routing/lib/system/route.js +++ b/packages/ember-routing/lib/system/route.js @@ -1845,6 +1845,7 @@ var Route = EmberObject.extend(ActionHandler, Evented, { disconnectOutlet: function(options) { var outletName; var parentView; + var parent; if (!options || typeof options === "string") { outletName = options; } else { @@ -1853,7 +1854,8 @@ var Route = EmberObject.extend(ActionHandler, Evented, { } parentView = parentView && parentView.replace(/\//g, '.'); - if (parentView === parentRoute(this).routeName) { + parent = parentRoute(this); + if (parent && parentView === parent.routeName) { parentView = undefined; } outletName = outletName || 'main'; diff --git a/packages/ember/tests/routing/basic_test.js b/packages/ember/tests/routing/basic_test.js index fc690b58e7e..7d467df9e4d 100644 --- a/packages/ember/tests/routing/basic_test.js +++ b/packages/ember/tests/routing/basic_test.js @@ -3500,6 +3500,38 @@ QUnit.test("Can render into a named outlet at the top level", function() { equal(Ember.$('#qunit-fixture').text(), "A-The index-B-Hello world-C", "initial render"); }); +QUnit.test("Can disconnect a named outlet at the top level", function() { + Ember.TEMPLATES.application = compile("A-{{outlet}}-B-{{outlet \"other\"}}-C"); + Ember.TEMPLATES.modal = compile("Hello world"); + Ember.TEMPLATES.index = compile("The index"); + + registry.register('route:application', Ember.Route.extend({ + renderTemplate: function() { + this.render(); + this.render('modal', { + into: 'application', + outlet: 'other' + }); + }, + actions: { + banish: function() { + this.disconnectOutlet({ + parentView: 'application', + outlet: 'other' + }); + } + } + })); + + bootApplication(); + + equal(Ember.$('#qunit-fixture').text(), "A-The index-B-Hello world-C", "initial render"); + + Ember.run(router, 'send', 'banish'); + + equal(Ember.$('#qunit-fixture').text(), "A-The index-B--C", "second render"); +}); + QUnit.test("Can render into a named outlet at the top level, with empty main outlet", function() { Ember.TEMPLATES.application = compile("A-{{outlet}}-B-{{outlet \"other\"}}-C"); Ember.TEMPLATES.modal = compile("Hello world");