Skip to content

Commit

Permalink
Revert making map return vanilla JS Array
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelrahmanHafez committed Nov 19, 2019
1 parent ba38d1d commit 4599877
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 8 deletions.
5 changes: 0 additions & 5 deletions lib/types/documentarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ class CoreDocumentArray extends CoreMongooseArray {
return arr;
}

map() {
const arr = [].concat(Array.prototype.map.apply(this,arguments));
return arr;
}

/**
* Wraps [`Array#push`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push) with proper change tracking.
*
Expand Down
4 changes: 1 addition & 3 deletions test/types.documentarray.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,15 +576,13 @@ describe('types.documentarray', function() {
assert.equal(doc.docs.length, 2);
});

it('map() works and does not return a mongoose array', function() {
it('map() works', function() {
const personSchema = new Schema({ friends: [{ name: { type: String } }]});
const Person = mongoose.model('gh8317-map', personSchema);

const person = new Person({ friends: [{ name: 'Hafez' }] });

const friendsNames = person.friends.map(friend => friend.name);
assert.deepEqual(friendsNames.constructor, Array);

friendsNames.push('Sam');

assert.equal(friendsNames.length, 2);
Expand Down

0 comments on commit 4599877

Please sign in to comment.