-
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
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 |
---|---|---|
|
@@ -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 = {}; | ||
|
||
var assertNotHasOwnProperty = function(name, context) { | ||
if (name === 'hasOwnProperty') { | ||
throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context); | ||
|
@@ -114,6 +117,37 @@ function setupModuleLoader(window) { | |
_configBlocks: configBlocks, | ||
_runBlocks: runBlocks, | ||
|
||
/** | ||
* @ngdoc method | ||
* @name angular.Module#info | ||
* @module ng | ||
* | ||
* @param {Object=} info Information about the module | ||
* @returns {Object|Module} The current info object for this module if called as a getter, | ||
* or `this` if called as a setter. | ||
* | ||
* @description | ||
* Additional info about this module | ||
* For example you could put the version of the module in here. | ||
* | ||
* ```js | ||
* angular.module('myModule', []).info({ version: '1.0.0' }); | ||
* ``` | ||
* | ||
* The global method `angular.info()` can be used to retrieve this info: | ||
* | ||
* ```js | ||
* var version = angular.info('myModule').version; | ||
* ``` | ||
*/ | ||
info: function(value) { | ||
if (isDefined(value)) { | ||
info = value; | ||
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. 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @ThomasBurleson - I would rather not 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. we could ensure that |
||
return this; | ||
} | ||
return info; | ||
}, | ||
|
||
/** | ||
* @ngdoc property | ||
* @name angular.Module#requires | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1614,6 +1614,21 @@ describe('angular', function() { | |
}); | ||
}); | ||
|
||
|
||
describe('info', function() { | ||
it('should return the additional info for the named module', function() { | ||
angular.module('a', []).info({some: 'thing'}); | ||
angular.module('b', ['dep'], function configFn() {}).info({other: 'thang'}); | ||
|
||
expect(info('a')).toEqual({some: 'thing'}); | ||
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. Where is the 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. It is defined in the closure and on 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. kk. The definition is in |
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
expect(info('no-such-module')).toEqual({}); | ||
}); | ||
}); | ||
|
||
describe('bootstrap', function() { | ||
it('should bootstrap app', function() { | ||
var element = jqLite('<div>{{1+2}}</div>'); | ||
|
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