Created
August 18, 2014 21:11
-
-
Save denisnazarov/f1849ad552ad7ccab7a0 to your computer and use it in GitHub Desktop.
Ember dynamic component helper: {{component foo}}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
Ember.Handlebars.registerHelper('component', function (name, options) { | |
var context = (options.contexts && options.contexts.length) ? options.contexts[0] : this; | |
if (options.types[0] === "ID") { | |
name = Ember.Handlebars.get(context, name, options); | |
} | |
var container = options.data.view.container; | |
var fullName = 'component:' + name; | |
var templateFullName = 'template:components/' + name; | |
var templateRegistered = container && container.has(templateFullName); | |
if (templateRegistered) { | |
container.injection(fullName, 'layout', templateFullName); | |
} | |
var Component = container.lookupFactory(fullName); | |
if (templateRegistered && !Component) { | |
container.register(fullName, Ember.Component); | |
Component = container.lookupFactory(fullName); | |
} | |
if (Component) { | |
return Ember.Handlebars.helpers.view.call(this, Component, options); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment