Skip to content

Commit 00ca67e

Browse files
vojtajinaIgorMinar
authored andcommitted
Issue angular#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 angular#51
1 parent 91b6c5f commit 00ca67e

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/Angular.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,18 @@ function inherit(parent, extra) {
281281
function noop() {}
282282
function identity($) {return $;}
283283
function valueFn(value) {return function(){ return value; };}
284+
284285
function extensionMap(angular, name, transform) {
285286
var extPoint;
286287
return angular[name] || (extPoint = angular[name] = function (name, fn, prop){
287288
name = (transform || identity)(name);
288289
if (isDefined(fn)) {
290+
if (isDefined(extPoint[name])) {
291+
foreach(extPoint[name], function(property, key) {
292+
if (key.charAt(0) == '$' && isUndefined(fn[key]))
293+
fn[key] = property;
294+
});
295+
}
289296
extPoint[name] = extend(fn, prop || {});
290297
}
291298
return extPoint[name];

test/AngularSpec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,23 @@ describe('angularJsConfig', function() {
280280
ie_compat_id: 'ng-ie-compat'});
281281
});
282282
});
283+
284+
describe('extensionMap', function() {
285+
it('should preserve $ properties on override', function() {
286+
var extension = extensionMap({}, 'fake');
287+
extension('first', {$one: true, $two: true});
288+
var result = extension('first', {$one: false, $three: true});
289+
290+
expect(result.$one).toBeFalsy();
291+
expect(result.$two).toBeTruthy();
292+
expect(result.$three).toBeTruthy();
293+
});
294+
295+
it('should not preserve non-angular properties', function() {
296+
var extension = extensionMap({}, 'fake');
297+
extension('first', {two: true});
298+
var result = extension('first', {$one: false, $three: true});
299+
300+
expect(result.two).not.toBeDefined();
301+
});
302+
});

0 commit comments

Comments
 (0)