Пасоны, как вам новый стиль ui?
function Module(name, parent) {
this.controllers = parent ? Object.create(parent.controllers) : {};
this.directives = parent ? Object.create(parent.directives) : {};
this.animations = parent ? Object.create(parent.animations) : {};
this.services = parent ? Object.create(parent.services) : {};
this.filters = parent ? Object.create(parent.filters) : {};
this.parent = parent;
this.modules = {};
this.name = name;
}
Module.prototype.$$init = function(element) {
var $compile = this.service('$compile');
var $scope = this.service('$scope');
$compile(element)($scope);
};
Module.prototype.module = function(name) {
var module = new Module(name, this);
this.modules[name] = module;
return module;
};
// TODO:
Module.prototype.directive = function(name, factory) {
if (factory) {
this.$$resource('directives', name, factory);
var directive = this.$$resource('directives', name);
if (!directive.restrict) {
directive.restrict = 'A';
}
}
return this.$$resource('directives', name);
};
Module.prototype.service = function(name, factory) {
return this.$$resource('services', name, factory);
};
Module.prototype.filter = function(name, factory) {
return this.$$resource('filters', name, factory);
};
Module.prototype.animation = function(name, factory) {
return this.$$resource('animations', name, factory);
};
Module.prototype.controller = function(name, controller) {
var $parseController = this.service('$parseController');
if (controller) {
this.controllers[name] = $parseController(controller);
return this;
}
var controller = this.controllers[name];
if (!controller) {
controller = $parseController(window[name]);
}
return controller;
};
Module.prototype.invoke = function(factory, context, locals) {
var self = this;
if (!locals) {
locals = {}
}
if (isArray(factory)) {
var inject = factory.slice();
factory = inject.pop();
factory['$inject'] = inject;
}
if (!factory['$inject']) {
var params = factory.toString().match(/\(([\s\S]*?)\)/)[1].match(/[\w$]+/img) || [];
factory['$inject'] = params;
}
locals['$module'] = this;
var services = factory['$inject'].map(function(injectName) {
return locals[injectName] || self.service(injectName);
});
return factory.apply(context, services);
};
Module.prototype.instantiate = function(factory, locals) {
var instance = Object.create(factory.prototype);
var returns = this.invoke(factory, instance, locals);
if (isObject(returns)) {
instance = returns;
}
return instance;
};
Module.prototype.$$resource = function(type, name, factory) {
if (factory) {
var resource = {
factory : factory,
instance: null
};
this[type][name] = resource;
return this;
}
var resource = this[type][name];
if (!resource) return null;
var instance = resource.instance;
if (!instance) {
var instance = this.invoke(resource.factory) || null;
resource.instance = instance;
}
return instance;
};