Skip to content

Commit

Permalink
use different approach
Browse files Browse the repository at this point in the history
since the handling of that is in the mongodb-core library we will use a different approach, wrapping the methods
  • Loading branch information
Robbilie authored Jun 8, 2017
1 parent 6e6ed59 commit 0e2610c
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,13 +1003,12 @@ define.classMethod('close', {callback: true, promise:true});
* @return {Cursor}
*/
Cursor.prototype.map = function(transform) {
if(this.cursorState.transforms === undefined) {
this.cursorState.transforms = {};
}
if(this.cursorState.transforms.doc === undefined) {
this.cursorState.transforms.doc = [];
if(this.cursorState.transforms && this.cursorState.transforms.doc) {
var oldTransform = this.cursorState.transforms.doc;
this.cursorState.transforms.doc = function (doc) { return transform(oldTransform(doc)); };
} else {
this.cursorState.transforms = { doc: transform };
}
this.cursorState.transforms.doc.push(transform);
return this;
}

Expand Down Expand Up @@ -1102,11 +1101,8 @@ Cursor.prototype._read = function() {
}

// If we provided a map function
if(self.cursorState.transforms && self.cursorState.transforms.doc && result != null) {
return self.push(self.cursorState.transforms.doc
.filter(function (transform) { return typeof transform === 'function'; })
.reduce(function (previous, current) { return current(previous); }, result)
);
if(self.cursorState.transforms && typeof self.cursorState.transforms.doc == 'function' && result != null) {
return self.push(self.cursorState.transforms.doc(result));
}

// Return the result
Expand Down

0 comments on commit 0e2610c

Please sign in to comment.