Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for namespacing and subcomponents through prototype in compo... #485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ SingletonComponentFactory.prototype.init = function(context) {
// Don't call the create method for singleton components
SingletonComponentFactory.prototype.create = function() {};

App.prototype.component = function(viewName, constructor) {
App.prototype.component = function(viewName, constructor, ns) {
if (typeof viewName === 'function') {
constructor = viewName;
viewName = null;
Expand All @@ -178,22 +178,34 @@ App.prototype.component = function(viewName, constructor) {
// Inherit from Component
extendComponent(constructor);

// Set namespace to the component if it's passed along
if(ns) constructor.prototype.ns = ns;

// Load template view from filename
if (constructor.prototype.view) {
var viewFilename = constructor.prototype.view;
viewName = constructor.prototype.name || path.basename(viewFilename, '.html');
if(ns) viewName = ns + ':' + viewName;
this.loadViews(viewFilename, viewName);

} else if (!viewName) {
if (constructor.prototype.name) {
viewName = constructor.prototype.name;
if(ns) viewName = ns + ':' + viewName;
var view = this.views.register(viewName);
view.template = templates.emptyTemplate;
} else {
throw new Error('No view name specified for component');
}
}

// Load sub components
var subComponents = constructor.prototype.components;
if (subComponents) {
for(var i = 0, len = subComponents.length; i < len; i++) {
this.component(null, subComponents[i], viewName);
}
}

// Associate the appropriate view with the component type
var view = this.views.find(viewName);
if (!view) {
Expand Down