Skip to content

Commit 6dae256

Browse files
wangxiaoleeyeh
authored andcommitted
AV.applicationProduction -> AV._config.applicationProduction and deprcated AV._isNullOrUndefined (#288)
* AV.applicationProduction -> AV._config.applicationProduction * Deprecated AV._isNullOrUndefined() * Only when choosing a test environment, set header X-LC-Prod. * Change AV._config.applicationProduction default value.
1 parent 9fdda66 commit 6dae256

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/object.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
const _ = require('underscore');
77
const AVError = require('./error');
88
const AVRequest = require('./request').request;
9+
const utils = require('./utils');
910

1011
// AV.Object is analogous to the Java AVObject.
1112
// It also implements the same interface as a Backbone model.
@@ -312,7 +313,7 @@ module.exports = function(AV) {
312313
}
313314
var val = this.attributes[attr];
314315
var escaped;
315-
if (AV._isNullOrUndefined(val)) {
316+
if (utils.isNullOrUndefined(val)) {
316317
escaped = '';
317318
} else {
318319
escaped = _.escape(val.toString());
@@ -328,7 +329,7 @@ module.exports = function(AV) {
328329
* @return {Boolean}
329330
*/
330331
has: function(attr) {
331-
return !AV._isNullOrUndefined(this.attributes[attr]);
332+
return !utils.isNullOrUndefined(this.attributes[attr]);
332333
},
333334

334335
/**
@@ -579,7 +580,7 @@ module.exports = function(AV) {
579580
*/
580581
set: function(key, value, options) {
581582
var attrs, attr;
582-
if (_.isObject(key) || AV._isNullOrUndefined(key)) {
583+
if (_.isObject(key) || utils.isNullOrUndefined(key)) {
583584
attrs = key;
584585
AV._objectEach(attrs, function(v, k) {
585586
attrs[k] = AV._decode(k, v);
@@ -859,7 +860,7 @@ module.exports = function(AV) {
859860
*/
860861
save: function(arg1, arg2, arg3) {
861862
var i, attrs, current, options, saved;
862-
if (_.isObject(arg1) || AV._isNullOrUndefined(arg1)) {
863+
if (_.isObject(arg1) || utils.isNullOrUndefined(arg1)) {
863864
attrs = arg1;
864865
options = arg2;
865866
} else {

src/request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ const setHeaders = (sessionToken) => {
9999
} else {
100100
headers['X-LC-Sign'] = sign(AV.applicationKey);
101101
}
102-
if (!AV._isNullOrUndefined(AV.applicationProduction)) {
103-
headers['X-LC-Prod'] = AV.applicationProduction;
102+
if (!AV._config.applicationProduction === null) {
103+
headers['X-LC-Prod'] = AV._config.applicationProduction;
104104
}
105105
if (!AV._config.isNode) {
106106
headers['X-LC-UA'] = `AV/${AV.version}`;

src/utils.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
const _ = require('underscore');
77
const request = require('./request');
88

9+
// Helper function to check null or undefined.
10+
const isNullOrUndefined = (x) => _.isNull(x) || _.isUndefined(x);
11+
912
const init = (AV) => {
1013
// 挂载一些配置
1114
const AVConfig = AV._config;
@@ -26,6 +29,10 @@ const init = (AV) => {
2629

2730
// Internal config can modifie the UserAgent
2831
userAgent: null,
32+
33+
// set production environment or test environment
34+
// 1: production environment, 0: test environment, null: default environment
35+
applicationProduction: null,
2936
});
3037

3138
/**
@@ -47,7 +54,6 @@ const init = (AV) => {
4754
// Shared empty constructor function to aid in prototype-chain creation.
4855
var EmptyConstructor = function() {};
4956

50-
5157
// Helper function to correctly set up the prototype chain, for subclasses.
5258
// Similar to `goog.inherits`, but uses a hash of prototype properties and
5359
// class properties to be extended.
@@ -177,13 +183,13 @@ const init = (AV) => {
177183
* @param {Boolean} production True is production environment,and
178184
* it's true by default.
179185
*/
180-
AV.setProduction = function(production){
181-
if(!AV._isNullOrUndefined(production)) {
182-
//make sure it's a number
183-
production = production ? 1 : 0;
186+
AV.setProduction = (production) => {
187+
if (!isNullOrUndefined(production)) {
188+
AVConfig.applicationProduction = production ? 1 : 0;
189+
} else {
190+
// change to default value
191+
AVConfig.applicationProduction = null;
184192
}
185-
//default is 1
186-
AV.applicationProduction = AV._isNullOrUndefined(production) ? 1: production;
187193
};
188194

189195
/**
@@ -540,13 +546,9 @@ const init = (AV) => {
540546
_.each(obj, callback);
541547
}
542548
};
543-
544-
// Helper function to check null or undefined.
545-
AV._isNullOrUndefined = function(x) {
546-
return _.isNull(x) || _.isUndefined(x);
547-
};
548549
};
549550

550551
module.exports = {
551552
init,
553+
isNullOrUndefined,
552554
};

0 commit comments

Comments
 (0)