-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(ngMock.$componentController): not increase extra bytes in angular.min.js #13732
Conversation
…ers for components Closes angular#13683
…ers for components Closes angular#13683
…w code to angular.min.js angular#13683
We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm. |
…ers for components Closes angular#13683 Closes angular#13711
Nice one @drpicox - I will tweak this (due to refactorings I did already) and merge it on top of what I just landed. |
Thanks, and thanks also for your code! (Oh, that's the reason of conflicts)
Btw, I do not understand why says cla:no, I have signed it on Jun 06, 2015 04:43 PDT
|
It says no because there are commits from you and me; and it is wants to check that you aren't just pushing someone else's code without their permission |
We can't use this on directives because the injector will only return a factory function for directives. |
One can only have a single component directive on an element, so having multiple component directives with the same name would not make sense. I am not sure what the injector will do if there are multiple directives with the same name. |
So it seems that's ok. |
The problem with this change is that it can't defferentiate between components and non-component directives and assumes. If there are non-component directives that have the same name as a component, then the order of registration will affect the behavior of Maybe we could add a private (as in $$-prefixed) property on components, so we can tell them apart. |
I agree that there are some potential issues with this approach. Let me have a play today. |
@gkalpak it is what I expected, but imho components are directives (sugar syntax), in fact they are registered as directives: Line 1092 in dd14e0c
this.component = function registerComponent(name, options) {
...
function factory($injector) {
...
return {
controller: controller,
controllerAs: ident,
template: makeInjectable(template),
templateUrl: makeInjectable(options.templateUrl),
transclude: options.transclude,
scope: {},
bindToController: options.bindings || {},
restrict: options.restrict || 'E'
};
}
...
return this.directive(name, factory);
}; Programmers might build "components" manually with If there is a directive with the same name than a component, it means that we have actually two directives with the same name. May be in this case the helper function should throw an error. If it would change in the future, and components become not implemented through directives, it may broke many codes, like many tests, and them must be fixed. The cool part is that we can add an alias for free called |
@drpicox, the "problem" is that multiple directives with the same name is a supported feature (and quite a useful one in several cases). That is the reason why it is not easy to implement this feature for "non-component" directives with predictable behavior. By "non-component" I mean directives that are not registered using the |
@gkalpak for what I understand you are not telling that the suggested implementation for testing is wrong, but the way to implement the directive is. I explain:
This code is working in the current implementation (both, 1.5.0-rc0 and current merged for 1.5.0-rc1): app.component('myComponent', {
controller: MyControllerAspect1,
});
app.component('myComponent', {
controller: MyControllerAspect2,
restrict: 'A',
}); In this case, the current implementation of This code is not working in 1.4.8: app.directive('myDirective', function() {
return {
controller: MyControllerAspect1,
controllerAs: 'aspect1',
};
});
app.directive('myDirective', function() {
return {
controller: MyControllerAspect2,
controllerAs: 'aspect2',
};
}); In order to avoid multiple controllers for the same component The other point to consider is what happens with decorators. It is legal to do: app.decorator('myComponentDirective', function($delegate) {
var directive = $delegate[0];
directive.controller = MyControllerAspect3;
return $delegate;
}); In such case, the original solution that I try to amend, in addition to save bytes in the angular.min.js, it also is getting the right controller, a controller that must satisfy the tested interface. So, there are the following ways to proceed:
How to implement
@petebacondarwin and @gkalpak any suggestion for which case should be applied? |
Includes the following fixes (per component): * `$sniffer`: Properly determine the expected `vendorPrefix` for MS Edge * `input`: MS Edge does not support dates with years with more than 4 digits. Trying to set the value of an `input[datetime-local]` to `9999-12-31T23.59.59.999` throws an error (probably related to converting the date to one with a year with more than 4 digits, due to timezone offset). * `$sanitize`: Fix failing tests on MS Edge * `$animateCss`: Although the detected `vendorPrefix` for MS Edge is "ms", it doesn't seem to recognize some vendor-prefixed CSS rules (e.g. `-ms-animation-*`). Other browsers (currently) recognize either vendor-prefixed rules only or both. Fixed by adding and retrieving styles using both prefixed and un-prefixed names. * `$compile`: Skip failing `foreignObject` test on MS Edge. For unknown reasons, an `<svg>` element inside a `<foreignObject>` element on MS Edge has no size, causing the included `<circle>` element to also have no size and thus fails an assertion (relying on the element having a non-zero size). This seems to be an MS Edge issue; i.e. it is also reproducible without Angular. (Tested with MS Edge version 25.10586.0.0 on Windows 10.) Closes angular#13686
@drpicox, indeed I missed that you can have several components with the same name. In that case, Maybe it's a good idea to only allow one component per "restrict" type (maybe even only allow I think we need to re-think |
Worse that that, rethink |
OK, so we should restrict |
Then the |
So Case 1. I'll try to do the changes later today. |
A bug in material has exposed that ngAnimate makes a copy of the provided animation options twice. By making two copies, the same DOM operations are performed during and at the end of the animation. If the CSS classes being added/ removed contain existing transition code, then this will lead to rendering issues. Closes angular#13722 Closes angular#13578
As discussed in angular#13664 (comment). Closes angular#13736
Fixed. |
@drpicox I guess you are trying to rebase? |
Yep! |
Rebase is my pending lesson in git. |
…g new code to angular.min.js Closes angular#13732
I made some changes to the solution of @petebacondarwin that closes #13683
Basically:
$$componentControllers
map from$controlerProvider
$injector
to get the component directive structureThe objective of these changes are: