mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
Issue #51: Update extensionMap()
If user override existing extension, angular properties ($) will be preserved. This piece of logic could be refactored into separate method: Something like we have extend(), addMissingProperties() - I can't find a name for this method... Closes #51
This commit is contained in:
parent
91b6c5f7ff
commit
00ca67e4be
2 changed files with 27 additions and 0 deletions
|
|
@ -281,11 +281,18 @@ function inherit(parent, extra) {
|
|||
function noop() {}
|
||||
function identity($) {return $;}
|
||||
function valueFn(value) {return function(){ return value; };}
|
||||
|
||||
function extensionMap(angular, name, transform) {
|
||||
var extPoint;
|
||||
return angular[name] || (extPoint = angular[name] = function (name, fn, prop){
|
||||
name = (transform || identity)(name);
|
||||
if (isDefined(fn)) {
|
||||
if (isDefined(extPoint[name])) {
|
||||
foreach(extPoint[name], function(property, key) {
|
||||
if (key.charAt(0) == '$' && isUndefined(fn[key]))
|
||||
fn[key] = property;
|
||||
});
|
||||
}
|
||||
extPoint[name] = extend(fn, prop || {});
|
||||
}
|
||||
return extPoint[name];
|
||||
|
|
|
|||
|
|
@ -280,3 +280,23 @@ describe('angularJsConfig', function() {
|
|||
ie_compat_id: 'ng-ie-compat'});
|
||||
});
|
||||
});
|
||||
|
||||
describe('extensionMap', function() {
|
||||
it('should preserve $ properties on override', function() {
|
||||
var extension = extensionMap({}, 'fake');
|
||||
extension('first', {$one: true, $two: true});
|
||||
var result = extension('first', {$one: false, $three: true});
|
||||
|
||||
expect(result.$one).toBeFalsy();
|
||||
expect(result.$two).toBeTruthy();
|
||||
expect(result.$three).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not preserve non-angular properties', function() {
|
||||
var extension = extensionMap({}, 'fake');
|
||||
extension('first', {two: true});
|
||||
var result = extension('first', {$one: false, $three: true});
|
||||
|
||||
expect(result.two).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue