Add a public "has" method to the Controller class, to check the existence of a given controller#14109
Add a public "has" method to the Controller class, to check the existence of a given controller#14109Vadorequest wants to merge 1 commit into
Conversation
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
1 similar comment
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
| globals = false; | ||
|
|
||
| /** | ||
| * @ngdoc method |
|
I left a couple of minor comments. There are also some styling issues that JSCS complains about (you can take a look here). Could you also add Regarding Regarding tests: |
|
CLAs look good, thanks! |
1 similar comment
|
CLAs look good, thanks! |
|
@gkalpak Thanks for feedback. I've pushed changes. I'm installing the environment on an Ubunutu now. I don't know what happened about gyp-rebuild but many node modules weren't properly installed after the red messages, I assumed it didn't go well. :) (I forgot about |
|
Great ! The code LGTM. Let us know if you run into any difficulties setting up the testing environment. |
|
I just pushed some tests, hope they'll pass. Not sure aboute the So, CI's got to do the testing part :) |
|
Are you by any chance using npm >=3.0.0 ? That would explain the |
|
There were some failures 😃 |
|
|
||
| $controllerProvider.register({FooCtrl: FooCtrl}); | ||
| expect($controllerProvider.has('BarCtrl')).toBe(false); | ||
| }); |
There was a problem hiding this comment.
I would basically merge both tests, into something like:
$controllerProvider.register('FooCtrl', noop);
expect($controllerProvider.has('FooCtrl')).toBe(true);
expect($controllerProvider.has('BarCtrl')).toBe(false);Or if we wanted to be more thorough, something like:
$controllerProvider.register('FooCtrl', noop);
$controllerProvider.register('BarCtrl', ['dep1', 'dep2', noop]);
$controllerProvider.register({
'BazCtrl': noop,
'QuxCtrl': ['dep1', 'dep2', noop]
});
expect($controllerProvider.has('FooCtrl')).toBe(true);
expect($controllerProvider.has('BarCtrl')).toBe(true);
expect($controllerProvider.has('BazCtrl')).toBe(true);
expect($controllerProvider.has('QuxCtrl')).toBe(true);
expect($controllerProvider.has('UnknownCtrl')).toBe(false);There was a problem hiding this comment.
I don't understand what noop is here, should I replace it by {}?
There was a problem hiding this comment.
Sorry, too much internals 😁
noop is basically angular.noop, which is basically function() {} (a no-op function). You can use noop as a shorthand for an empty constructor function. For this functionality, you don't need to pass any arguments to the controller, nor does the controller need to have any logic.
|
@Vadorequest, do you think it would be useful to have the method available on |
|
@gkalpak No, I don't think the controller needs to have a |
|
Tests passed :) Cool. And yes, I'm using node 5.5, that's why it fails during the setup. |
56854da to
11a9111
Compare
|
Using node 3.3.1 it worked well, I've been able to run the tests and everything looks good. |
|
|
||
| it('should return true when having an existing controller, should return false otherwise', function() { | ||
| var FooCtrl = function($scope) { $scope.foo = 'foo'; }, | ||
| BarCtrl = function($scope) { $scope.bar = 'bar'; }; |
There was a problem hiding this comment.
We don't need these two controllers, do we ?
There was a problem hiding this comment.
Indeed! I just removed them.
|
@Vadorequest, only a minor clean-up comment. LGTM otherwise 👍 |
…ss, to check the existence of a given controller. Fixes angular#13951
11a9111 to
bcaa151
Compare
|
Thx @Vadorequest 👍 |
|
Thanks to you @gkalpak :) |
|
It will be available from the upcoming |
|
Thanks ;) |
I haven't written any test. The
npm installfailed here and I've been unable to test anything. (Seems like it fails on gyp-rebuild with my WIndows 8.1...)The PR is quite small. if someone with a proper setup could just add some test for it, it would be nice.
#13951