Skip to content

Commit

Permalink
Use bluebird in utils.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jannyHou committed Jan 5, 2016
1 parent 5cf37aa commit ede1050
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 20 deletions.
6 changes: 6 additions & 0 deletions 3.0-RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ always describe the impact on users and instructions for upgrading
applications from 2.x to 3.0.

See also https://github.com/strongloop/loopback/blob/master/3.0-DEVELOPING.md

## Always use bluebird as promise library

In version 3.0, we always use bluebird as promise library instead of the default promise library in javascript.

[Related code change](https://github.com/strongloop/loopback-datasource-juggler/pull/790)
2 changes: 1 addition & 1 deletion lib/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ function defineScope(cls, targetClass, name, params, methods, options) {
}
}
}

options = options || {};
filter = filter || {};
var targetModel = definition.targetModel(this._receiver);
Expand Down
16 changes: 1 addition & 15 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports.findIndexOf = findIndexOf;

var traverse = require('traverse');
var assert = require('assert');
var Promise = require('bluebird');

function safeRequire(module) {
try {
Expand Down Expand Up @@ -478,15 +479,6 @@ function sortObjectsByIds(idName, ids, objects, strict) {

function createPromiseCallback() {
var cb;

if (!global.Promise) {
cb = function(){};
cb.promise = {};
Object.defineProperty(cb.promise, 'then', { get: throwPromiseNotDefined });
Object.defineProperty(cb.promise, 'catch', { get: throwPromiseNotDefined });
return cb;
}

var promise = new Promise(function (resolve, reject) {
cb = function (err, data) {
if (err) return reject(err);
Expand All @@ -497,12 +489,6 @@ function createPromiseCallback() {
return cb;
}

function throwPromiseNotDefined() {
throw new Error(
'Your Node runtime does support ES6 Promises. ' +
'Set "global.Promise" to your preferred implementation of promises.');
}

/**
* Dedupe an array
* @param {Array} an array
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
"node >= 0.6"
],
"devDependencies": {
"bluebird": "^2.9.9",
"mocha": "^2.1.0",
"should": "^8.0.2"
},
"dependencies": {
"async": "~1.0.0",
"bluebird": "^3.1.1",
"debug": "^2.1.1",
"depd": "^1.0.0",
"inflection": "^1.6.0",
Expand Down
1 change: 1 addition & 0 deletions test/async-observer.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var ModelBuilder = require('../').ModelBuilder;
var should = require('./init');
var Promise = require('bluebird');

describe('async observer', function() {
var TestModel;
Expand Down
3 changes: 0 additions & 3 deletions test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,3 @@ if (!('getModelBuilder' in global)) {
};
}

if (!('Promise' in global)) {
global.Promise = require('bluebird');
}

0 comments on commit ede1050

Please sign in to comment.