Skip to content

Commit

Permalink
BREAKING CHANGE: use native promises rather than mpromise by default
Browse files Browse the repository at this point in the history
Fix #2917
  • Loading branch information
vkarpov15 committed Dec 12, 2017
1 parent 6946d2b commit 938dd09
Show file tree
Hide file tree
Showing 29 changed files with 116 additions and 1,833 deletions.
26 changes: 0 additions & 26 deletions lib/ES6Promise.js

This file was deleted.

5 changes: 3 additions & 2 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ Connection.prototype.openUri = function(uri, options, callback) {

this._connectionOptions = options;

var promise = new Promise.ES6((resolve, reject) => {
var promise = new Promise((resolve, reject) => {
parser(uri, options, (error, parsed) => {
if (error) {
callback && callback(error);
Expand Down Expand Up @@ -563,7 +563,8 @@ Connection.prototype.model = function(name, schema, collection) {
this.models[name] = model;
}

model.init();
// Errors handled internally, so safe to ignore error
model.init(() => {});
return model;
}

Expand Down
13 changes: 0 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,19 +613,6 @@ Object.defineProperty(Mongoose.prototype, 'Promise', {
}
});

/**
* Returns the current ES6-style promise constructor. In Mongoose 4.x,
* equivalent to `mongoose.Promise.ES6`, but will change once we get rid
* of the `.ES6` bit.
*
* @method Promise
* @api public
*/

Mongoose.prototype.getPromiseConstructor = function() {
return PromiseProvider.get().ES6;
};

/**
* Storage layer for mongoose promises
*
Expand Down
13 changes: 4 additions & 9 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ Model.init = function init(callback) {

var _this = this;
var Promise = PromiseProvider.get();
this.$init = new Promise.ES6(function(resolve, reject) {
this.$init = new Promise(function(resolve, reject) {
if ((_this.schema.options.autoIndex) ||
(_this.schema.options.autoIndex == null && _this.db.config.autoIndex)) {
_this.ensureIndexes({ _automatic: true }, function(error) {
Expand Down Expand Up @@ -2016,13 +2016,7 @@ Model.create = function create(doc, callback) {
}
}

// Hack to avoid getting a promise because of
// $__registerHooksFromSchema
if (toSave.$__original_save) {
toSave.$__original_save({ __noPromise: true }, callbackWrapper);
} else {
toSave.save({ __noPromise: true }, callbackWrapper);
}
toSave.save(callbackWrapper);
});
});

Expand Down Expand Up @@ -3908,7 +3902,8 @@ Model.__subclass = function subclass(conn, schema, collection) {

Model.prototype.collection = conn.collection(collection, collectionOptions);
Model.collection = Model.prototype.collection;
Model.init();
// Errors handled internally, so ignore
Model.init(() => {});
return Model;
};

Expand Down
Loading

0 comments on commit 938dd09

Please sign in to comment.