Skip to content

Commit 7c86683

Browse files
committed
fix: use packaged Promise because AV.Promise might be overwrited
1 parent 7b97d3c commit 7c86683

File tree

9 files changed

+25
-23
lines changed

9 files changed

+25
-23
lines changed

src/av.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const _ = require('underscore');
22
const userAgent = require('./ua');
33
const { inherits, parseDate } = require('./utils');
4+
const Promise = require('./promise');
45

56
const AV = global.AV || {};
67

@@ -63,7 +64,7 @@ AV._installationId = null;
6364
AV._getInstallationId = () => {
6465
// See if it's cached in RAM.
6566
if (AV._installationId) {
66-
return AV.Promise.resolve(AV._installationId);
67+
return Promise.resolve(AV._installationId);
6768
}
6869

6970
// Try to get it from localStorage.
@@ -91,7 +92,7 @@ AV._refreshSubscriptionId = (path = AV._getAVPath('subscriptionId')) => {
9192
AV._getSubscriptionId = () => {
9293
// See if it's cached in RAM.
9394
if (AV._subscriptionId) {
94-
return AV.Promise.resolve(AV._subscriptionId);
95+
return Promise.resolve(AV._subscriptionId);
9596
}
9697

9798
// Try to get it from localStorage.

src/geopoint.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var _ = require('underscore');
2+
const Promise = require('./promise');
23

34
/*global navigator: false */
45
module.exports = function(AV) {
@@ -99,7 +100,7 @@ module.exports = function(AV) {
99100
* @return {Promise.<AV.GeoPoint>}
100101
*/
101102
AV.GeoPoint.current = () =>
102-
new AV.Promise((resolve, reject) => {
103+
new Promise((resolve, reject) => {
103104
navigator.geolocation.getCurrentPosition(function(location) {
104105
resolve(
105106
new AV.GeoPoint({

src/insight.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const _ = require('underscore');
22
const AVError = require('./error');
33
const { request } = require('./request');
4+
const Promise = require('./promise');
45

56
module.exports = function(AV) {
67
/**
@@ -129,11 +130,9 @@ module.exports = function(AV) {
129130
signKey: false,
130131
}).then(function(response) {
131132
if (response.error) {
132-
return AV.Promise.reject(
133-
new AVError(response.code, response.error)
134-
);
133+
return Promise.reject(new AVError(response.code, response.error));
135134
}
136-
return AV.Promise.resolve(response);
135+
return Promise.resolve(response);
137136
});
138137
},
139138
}

src/object.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const _ = require('underscore');
22
const AVError = require('./error');
3+
const Promise = require('./promise');
34
const { _request } = require('./request');
45
const {
56
isNullOrUndefined,
@@ -144,7 +145,7 @@ module.exports = function(AV) {
144145
*/
145146

146147
AV.Object.fetchAll = (objects, options) =>
147-
AV.Promise.resolve()
148+
Promise.resolve()
148149
.then(() =>
149150
_request(
150151
'batch',
@@ -978,7 +979,7 @@ module.exports = function(AV) {
978979
* @param {AuthOptions} options AuthOptions plus:
979980
* @param {Boolean} options.fetchWhenSave fetch and update object after save succeeded
980981
* @param {AV.Query} options.query Save object only when it matches the query
981-
* @return {AV.Promise} A promise that is fulfilled when the save
982+
* @return {Promise} A promise that is fulfilled when the save
982983
* completes.
983984
* @see AVError
984985
*/
@@ -1018,7 +1019,7 @@ module.exports = function(AV) {
10181019
this._startSave();
10191020
this._saving = (this._saving || 0) + 1;
10201021

1021-
this._allPreviousSaves = this._allPreviousSaves || AV.Promise.resolve();
1022+
this._allPreviousSaves = this._allPreviousSaves || Promise.resolve();
10221023
this._allPreviousSaves = this._allPreviousSaves
10231024
.catch(e => {})
10241025
.then(function() {
@@ -1400,7 +1401,7 @@ module.exports = function(AV) {
14001401
*/
14011402
AV.Object.destroyAll = function(objects, options = {}) {
14021403
if (!objects || objects.length === 0) {
1403-
return AV.Promise.resolve();
1404+
return Promise.resolve();
14041405
}
14051406
const objectsByClassNameAndFlags = _.groupBy(objects, object =>
14061407
JSON.stringify({
@@ -1655,7 +1656,7 @@ module.exports = function(AV) {
16551656
var unsavedFiles = [];
16561657
AV.Object._findUnsavedChildren(object, unsavedChildren, unsavedFiles);
16571658

1658-
var promise = AV.Promise.resolve();
1659+
var promise = Promise.resolve();
16591660
_.each(unsavedFiles, function(file) {
16601661
promise = promise.then(function() {
16611662
return file.save();
@@ -1667,7 +1668,7 @@ module.exports = function(AV) {
16671668

16681669
return promise
16691670
.then(function() {
1670-
return AV.Promise._continueWhile(
1671+
return Promise._continueWhile(
16711672
function() {
16721673
return remaining.length > 0;
16731674
},
@@ -1692,7 +1693,7 @@ module.exports = function(AV) {
16921693

16931694
// If we can't save any objects, there must be a circular reference.
16941695
if (batch.length === 0) {
1695-
return AV.Promise.reject(
1696+
return Promise.reject(
16961697
new AVError(
16971698
AVError.OTHER_CAUSE,
16981699
'Tried to save a batch with a cycle.'
@@ -1701,9 +1702,9 @@ module.exports = function(AV) {
17011702
}
17021703

17031704
// Reserve a spot in every object's save queue.
1704-
var readyToStart = AV.Promise.resolve(
1705+
var readyToStart = Promise.resolve(
17051706
_.map(batch, function(object) {
1706-
return object._allPreviousSaves || AV.Promise.resolve();
1707+
return object._allPreviousSaves || Promise.resolve();
17071708
})
17081709
);
17091710

src/query.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ module.exports = function(AV) {
10131013
var error = new Error(
10141014
'Cannot iterate on a query with sort, skip, or limit.'
10151015
);
1016-
return AV.Promise.reject(error);
1016+
return Promise.reject(error);
10171017
}
10181018

10191019
var query = new AV.Query(this.objectClass);
@@ -1026,13 +1026,13 @@ module.exports = function(AV) {
10261026
query.ascending('objectId');
10271027

10281028
var finished = false;
1029-
return AV.Promise._continueWhile(
1029+
return Promise._continueWhile(
10301030
function() {
10311031
return !finished;
10321032
},
10331033
function() {
10341034
return query.find(options).then(function(results) {
1035-
var callbacksDone = AV.Promise.resolve();
1035+
var callbacksDone = Promise.resolve();
10361036
_.each(results, function(result) {
10371037
callbacksDone = callbacksDone.then(function() {
10381038
return callback(result);

src/search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ module.exports = function(AV) {
226226
* completes.
227227
*
228228
* @see AV.Query#find
229-
* @return {AV.Promise} A promise that is resolved with the results when
229+
* @return {Promise} A promise that is resolved with the results when
230230
* the query completes.
231231
*/
232232
find: function() {

src/status.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module.exports = function(AV) {
6565
*/
6666
destroy: function(options) {
6767
if (!this.id)
68-
return AV.Promise.reject(new Error('The status id is not exists.'));
68+
return Promise.reject(new Error('The status id is not exists.'));
6969
var request = AVRequest('statuses', null, this.id, 'DELETE', options);
7070
return request;
7171
},

test/file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('File', function() {
112112
expect(file.size()).to.be(9);
113113
expect(file.ownerId()).to.be.ok();
114114
expect(file.id).to.be.ok();
115-
return new AV.Promise(function(resolve, reject) {
115+
return new Promise(function(resolve, reject) {
116116
request(file.url()).end(function(err, res) {
117117
if (err) {
118118
return reject(err);

test/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ describe('Queries', function() {
332332
test.set('number', i);
333333
promises.unshift(test.save());
334334
}
335-
return AV.Promise.all(promises)
335+
return Promise.all(promises)
336336
.then(function() {
337337
return new AV.Query('deletedAll').limit(300).destroyAll();
338338
})

0 commit comments

Comments
 (0)