Skip to content

Commit

Permalink
Merge pull request #16853 from nlfurniss/fix-array-push
Browse files Browse the repository at this point in the history
[BUGFIX beta] Allow ArrayProxy#pushObjects to accept ArrayProxy again
  • Loading branch information
rwjblue committed Aug 1, 2018
2 parents b641131 + 1d9d1dd commit 24ce7de
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 2 additions & 3 deletions packages/ember-runtime/lib/mixins/array.js
Expand Up @@ -1194,6 +1194,8 @@ const MutableArray = Mixin.create(ArrayMixin, MutableEnumerable, {
You should replace amt objects started at idx with the objects in the
passed array. You should also call `this.arrayContentDidChange()`
Note that this method is expected to validate the type(s) of objects that it expects.
@method replace
@param {Number} idx Starting index in the array to replace. If
idx >= length, then append to the end of the array.
Expand Down Expand Up @@ -1318,9 +1320,6 @@ const MutableArray = Mixin.create(ArrayMixin, MutableEnumerable, {
@public
*/
pushObjects(objects) {
if (!Array.isArray(objects)) {
throw new TypeError('Must pass Enumerable to MutableArray#pushObjects');
}
this.replace(this.length, 0, objects);
return this;
},
Expand Down
2 changes: 2 additions & 0 deletions packages/ember-runtime/lib/system/array_proxy.js
Expand Up @@ -133,6 +133,8 @@ export default class ArrayProxy extends EmberObject {
return objectAt(get(this, 'arrangedContent'), idx);
}

// See additional docs for `replace` from `MutableArray`:
// https://www.emberjs.com/api/ember/3.3/classes/MutableArray/methods/replace?anchor=replace
replace(idx, amt, objects) {
assert(
'Mutating an arranged ArrayProxy is not allowed',
Expand Down
Expand Up @@ -5,7 +5,7 @@ class PushObjectsTests extends AbstractTestCase {
'@test should raise exception if not Ember.Enumerable is passed to pushObjects'() {
let obj = this.newObject([]);

this.assert.throws(() => obj.pushObjects('string'));
expectAssertion(() => obj.pushObjects('string'));
}
}

Expand Down

0 comments on commit 24ce7de

Please sign in to comment.