Permalink
Browse files

Add disconnectOutlet method to controller

  • Loading branch information...
tchak committed Aug 15, 2012
1 parent a2caaa3 commit 933b2b4a6eb4f82884c4ec5c567890ffb458beab
@@ -132,8 +132,10 @@ Ember.ControllerMixin.reopen(/** @scope Ember.ControllerMixin.prototype */ {
Ember.assert("The name you supplied " + name + " did not resolve to a controller " + name + 'Controller', (!!controller && !!context) || !context);
}
if (controller && context) { controller.set('content', context); }
view = viewClass.create();
if (controller && context) { set(controller, 'content', context); }
view = this.createOutletView(outletName, viewClass);
if (controller) { set(view, 'controller', controller); }
set(this, outletName, view);
@@ -160,6 +162,25 @@ Ember.ControllerMixin.reopen(/** @scope Ember.ControllerMixin.prototype */ {
controllerName = controllerNames[i] + 'Controller';
set(this, controllerName, get(controllers, controllerName));
}
},
/**
`disconnectOutlet` removes previously attached view from given outlet.
@param {String} outletName the outlet name. (optional)
*/
disconnectOutlet: function(outletName) {
outletName = outletName || 'view';
set(this, outletName, null);
},
/**
`createOutletView` is a hook you may want to override if you need to do
something special with the view created for the outlet. For example
you may want to implement views sharing across outlets.
*/
createOutletView: function(outletName, viewClass) {
return viewClass.create();
}
});
@@ -183,3 +183,26 @@ test("connectControllers injects other controllers", function() {
equal(controller.get('postController'), postController, "should connect postController");
equal(controller.get('commentController'), commentController, "should connect commentController");
});
test("can disconnect outlet from controller", function() {
var appController = TestApp.ApplicationController.create({
controllers: {},
namespace: TestApp
});
var view = appController.connectOutlet('post');
equal(appController.get('view'), view, "the app controller's view is set");
appController.disconnectOutlet();
equal(appController.get('view'), null, "the app controller's view is null");
view = appController.connectOutlet({outletName: 'master', name: 'post'});
equal(appController.get('master'), view, "the app controller's master view is set");
appController.disconnectOutlet('master');
equal(appController.get('master'), null, "the app controller's master view is null");
});

0 comments on commit 933b2b4

Please sign in to comment.