Skip to content

Commit

Permalink
ensure we don’t needlessly scan the concatenated properties array
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner committed Oct 15, 2014
1 parent fbf91df commit ad5df21
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/ember-metal/lib/mixin.js
Expand Up @@ -194,7 +194,11 @@ function applyConcatenatedProperties(obj, key, value, values) {

if (baseValue) {
if ('function' === typeof baseValue.concat) {
return baseValue.concat(value);
if (value === null || value === undefined) {
return baseValue;
} else {
return baseValue.concat(value);
}
} else {
return makeArray(baseValue).concat(value);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/ember-metal/tests/mixin/concatenatedProperties_test.js
Expand Up @@ -15,6 +15,22 @@ test('defining concatenated properties should concat future version', function()
deepEqual(Ember.get(obj, 'foo'), ['a', 'b', 'c', 'd', 'e', 'f']);
});

test('defining concatenated properties should concat future version', function() {

var MixinA = Ember.Mixin.create({
concatenatedProperties: null,
});

var MixinB = Ember.Mixin.create({
concatenatedProperties: null,
});

var obj = Ember.mixin({}, MixinA, MixinB);

deepEqual(obj.concatenatedProperties, []);
});


test('concatenatedProperties should be concatenated', function() {

var MixinA = Ember.Mixin.create({
Expand Down
4 changes: 3 additions & 1 deletion packages/ember-runtime/lib/system/core_object.js
Expand Up @@ -132,7 +132,9 @@ function makeCtor() {
"time, when Ember.ActionHandler is used (i.e. views, " +
"controllers & routes).", !((keyName === 'actions') && ActionHandler.detect(this)));

if (concatenatedProperties && indexOf(concatenatedProperties, keyName) >= 0) {
if (concatenatedProperties &&
concatenatedProperties.length > 0 &&
indexOf(concatenatedProperties, keyName) >= 0) {
var baseValue = this[keyName];

if (baseValue) {
Expand Down

0 comments on commit ad5df21

Please sign in to comment.