-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(angular.info): optionally store and access additional info on mo… #12465
Conversation
71e9b84
to
afc48a6
Compare
This approach may solve the issue of getting some meta-data out of a module (if a new bootstrap is made). On the other hand, given that it is possible to have modules redefinition, there would be no mechanism to see the metadata of the instance of a module that is used in any given |
The primary use case came from Angular Material, where they wanted to publish the version of the module so that when you are debugging some app, you can quickly drop into the browser console and see what versions are loaded. |
@lgalfaso is it common to load a module, create an injector, override the module with a new module and then create another injector in a single application? |
afc48a6
to
420fc61
Compare
angular.module('a', [], {some: 'thing'}); | ||
angular.module('b', ['dep'], {other: 'thang'}, function configFn() {}); | ||
|
||
expect(info('a')).toEqual({some: 'thing'}); |
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.
Where is the info()
defined ?
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.
It is defined in the closure and on angular
so we could make this test more clear.
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.
kk. The definition is in src/Angular.js
.
@petebacondarwin - The function signature return function module(name, requires, configFnOrInfo, configFn) {
}; looks like it will present issues Angular Material using Angular versions <1.4.4; ngMaterial would have to pre-check the registration call using It appears that an alternative signature would not require an argument count precheck. return function module(name, requires, configFn, info) {
};
|
The |
I think that the intention of the comment is that if someone wants to make a module that is 1.4.3 and 1.4.4 compatible, then, to be safe, would need to put the |
For apps where there are multiple non-trivial angular apps running at the same time and browserify (or any of the similar libraries are used), then the chances of having a module redefinition is quite high (even when in most cases the redefinition is just to a slightly different version of the same module (eg ui-router). I think that this falls into the less than 5% of the cases. That said, I do not think it would be a more code to make it work as |
@lgalfaso but both the old ( angular.module(moduleName, depencencyArray, configFn); I know that it is the norm to add new parameters to the end of the argument list but when both are optional then it doesn't make much difference. In this case, I believe that it is more pleasant, if you are going to provide both angular.module('someModule`, ['someDependency'], {version: '1.0.2'}, function() {
...
}); |
@petebacondarwin I am just saying that, if people want to be safe, then they will need to put the Note: If people have complete control of the environment their module will run, then this is not an issue, but this is an issue for material design as they should work fine with angular 1.4.3 |
Oh right! The concern is that people using this feature will cause their modules to be incompatible with previous versions of angular. This would still be the case if we add it as a fourth parameter but the user chooses not to provide a configFn. So I think we should move this out of the module function and have it as a method. |
…dules This feature allows the developer to store additional meta data about a module when it is defined by calling `mod.info(infoObject)` on the module object. Developers can then access this information by calling `mod.info()` or `angular.info(moduleName)`. See this angular/material#3842 for more background. Closes angular#12465
420fc61
to
51f8a57
Compare
*/ | ||
info: function(value) { | ||
if (isDefined(value)) { | ||
info = value; |
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 think we should do
info = angular.extend(info, angular.isObject(value) ? value : {});
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.
That would mean one could add to the info but never remove anything, right?
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.
@ThomasBurleson - I would rather not use extend
here. Can you give a concrete use case?
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.
angular
.module('ngMaterial',['ngAnimate'])
.info({
version : "1.0",
name : "Angular Material"
});
// Later during runtime
var info = angular.info().ngMaterial;
info.license = "MIT";
The goal of the
info = angular.extend(info, angular.isObject(value) ? value : {});
was to require that a hashamp object was registered not just a simply value.
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.
we could ensure that value
is an object with a check for isObject
, rather than using extend()
.
What if angular.info() returned a map with all available module names as keys and an object with module specific data (or an empty object if no data is provided). that way it's easy to see what's available without many angular.info(moduleName) calls. |
I think both would be great:
@IgorMinar - thoughts? |
|
@IgorMinar - Agreed: superfluous. |
@@ -79,6 +79,9 @@ function setupModuleLoader(window) { | |||
* @returns {module} new module with the {@link angular.Module} api. | |||
*/ | |||
return function module(name, requires, configFn) { | |||
|
|||
var info = {}; |
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.
probably better to use a createMap()
call here
expect(info('b')).toEqual({other: 'thang'}); | ||
}); | ||
|
||
it('should return anh empty object if there is no such module', function() { |
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.
typo
Closing in favour of #15225 |
…dules
This feature allows the developer to store additional meta data about a
module when it is defined by adding an additional parameter containing
an object to the
angular.module(moduleName, deps, info, configFn)
call.Developers can then access this information by calling
angular.info(moduleName)
See this angular/material#3842 for more background.