-
Notifications
You must be signed in to change notification settings - Fork 27.4k
WIP angular.component implementation [ci skip] #12166
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -812,6 +812,52 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |
} | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @name $compileProvider#component | ||
* @kind function | ||
* | ||
* @description | ||
* Register a new component with the compiler. | ||
* | ||
* A component is a shorthand for a directive with a controller, template, and a | ||
* new scope. | ||
* | ||
* @returns {ng.$compileProvider} Self for chaining. | ||
*/ | ||
this.component = registerComponent; | ||
function registerComponent(name, bindings, controller) { | ||
if (isString(name)) { | ||
assertValidDirectiveName(name); | ||
if (arguments.length < 3) { | ||
controller = bindings; | ||
bindings = controller.bindings || null; | ||
} | ||
return registerDirective(name, valueFn({ | ||
controller: controller, | ||
controllerAs: controller.controllerAs || '$' + name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed - when I created a similar approach, we'd just done a bunch of work with React. We called it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Horrible terrible no good but very flexible idea: let users specify the default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah we need to really figure out what we want to do here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see ngUpgraders/ng-forward#6 for discussion on configuration in that decorators implementation |
||
scope: controller.isolate ? {} : true, | ||
bindToController: bindings, | ||
template: controller.template || false, | ||
templateUrl: controller.templateUrl || false | ||
}, true)); | ||
} else { | ||
forEach(name, function(value, name) { | ||
var controller = null; | ||
var bindings = null; | ||
if (isArray(value) || isFunction(value)) { | ||
controller = value; | ||
bindings = value.bindings || null; | ||
} else if (isObject(value)) { | ||
controller = value.controller || null; | ||
bindings = value.bindings || null; | ||
} | ||
return registerComponent(name, bindings, controller); | ||
}); | ||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* @ngdoc method | ||
* @name $compileProvider#directive | ||
|
@@ -827,7 +873,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |
* {@link guide/directive} for more info. | ||
* @returns {ng.$compileProvider} Self for chaining. | ||
*/ | ||
this.directive = function registerDirective(name, directiveFactory) { | ||
this.directive = function callRegisterDirective(name, directiveFactory) { | ||
return registerDirective(name, directiveFactory, false); | ||
}; | ||
function registerDirective(name, directiveFactory, isComponent) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not enough space for |
||
assertNotHasOwnProperty(name, 'directive'); | ||
if (isString(name)) { | ||
assertValidDirectiveName(name); | ||
|
@@ -850,6 +899,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |
directive.name = directive.name || name; | ||
directive.require = directive.require || (directive.controller && directive.name); | ||
directive.restrict = directive.restrict || 'EA'; | ||
directive.component = !!isComponent; | ||
var bindings = directive.$$bindings = | ||
parseDirectiveBindings(directive, directive.name); | ||
if (isObject(bindings.isolateScope)) { | ||
|
@@ -869,7 +919,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |
forEach(name, reverseParams(registerDirective)); | ||
} | ||
return this; | ||
}; | ||
} | ||
|
||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this going to be called by
registerDirective()
anyway ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather see the error thrown in the registration method I call, rather than the underlying implementation.