-
Notifications
You must be signed in to change notification settings - Fork 27.4k
WIP angular.component implementation [ci skip] #12166
Conversation
Needs tests and experimentation, it would be nice to make this work well with TypeScript decorators for ease of use. The whole "controller instantiated after templateUrl is loaded" thing seems not-ideal, it would be cool if a templateUrl function could be a method of the component controller.
this.component = registerComponent; | ||
function registerComponent(name, bindings, controller) { | ||
if (isString(name)) { | ||
assertValidDirectiveName(name); |
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.
By having the controller by some sort of configuration object, we are restricting the use of a string in certain cases (which might not be a good practice). I would probably prefer an optional config object as a 4th parameter. |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Not enough space for this.directive
?
Would it be possible to get docs on what usage of this API is going to look like? It's hard to visualize just looking at the code... |
I envision it as using some kind of decorator library (we used to have a.js but that seems to have vanished somewhere), something like: // TypeScript decorators:
@Component({
templateUrl: 'meow.html',
controllerAs: 'MEOWCTRL'
})
class MeowComponent {
constructor() {
// Do important controller-initialization-stuff!
}
}
// ES5 JS with some kind of a.js-like library
Decorate(MeowComponent).With(Component, {
templateUrl: 'meow.html',
controllerAs: 'MEOWCTRL'
});
function MeowComponent() {
// Do important controller-initialization stuff!
} But you know, we are kind of just making it up as we go. No docs yet, I'll have to put more work into this before it gets that far |
Closing in favor of #12933 |
Needs tests and experimentation, it would be nice to make this work well
with TypeScript decorators for ease of use.
The whole "controller instantiated after templateUrl is loaded" thing seems
not-ideal, it would be cool if a templateUrl function could be a method of
the component controller.