Micro optimizations to {{plugin-outlet}}.

* Don't create a `ContainerView` if there is only one connection.

* Don't create a virtual view if there are no connectors and the
  block form of the plugin isn't used.
This commit is contained in:
Robin Ward 2014-06-18 14:04:08 -04:00
parent 8f2d1f7020
commit 61fb0f736b

View file

@ -2,6 +2,8 @@
A plugin outlet is an extension point for templates where other templates can A plugin outlet is an extension point for templates where other templates can
be inserted by plugins. be inserted by plugins.
## Usage
If you handlebars template has: If you handlebars template has:
```handlebars ```handlebars
@ -27,6 +29,16 @@
And it will be wired up automatically. And it will be wired up automatically.
## The block form
If you use the block form of the outlet, its contents will be displayed
if no connectors are found. Example:
```handlebars
{{#plugin-outlet "hello-world"}}
Nobody says hello :'(
{{/plugin-outlet}}
```
**/ **/
var _connectorCache; var _connectorCache;
@ -77,13 +89,24 @@ export default function(connectionName, options) {
var self = this; var self = this;
if (_connectorCache[connectionName]) { if (_connectorCache[connectionName]) {
var CustomContainerView = Ember.ContainerView.extend({ var view,
childViews: _connectorCache[connectionName].map(function(vc) { childViews = _connectorCache[connectionName].map(function(vc) {
return vc.create({context: self}); return vc.create({ context: self });
}) });
});
return Ember.Handlebars.helpers.view.call(this, CustomContainerView, options); // If there is more than one view, create a container. Otherwise
} else { // just shove it in.
if (childViews.length > 1) {
view = Ember.ContainerView.extend({
childViews: childViews
});
} else {
view = childViews[0];
}
return Ember.Handlebars.helpers.view.call(this, view, options);
} else if (options.fn) {
// If a block is passed, render its content.
return Ember.Handlebars.helpers.view.call(this, return Ember.Handlebars.helpers.view.call(this,
Ember.View.extend({ Ember.View.extend({
isVirtual: true, isVirtual: true,