Skip to content

Commit 89ba743

Browse files
committed
chore(release): v1.4.0-beta.0
1 parent 782cbfe commit 89ba743

File tree

14 files changed

+201
-53
lines changed

14 files changed

+201
-53
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "leancloud-storage",
3-
"version": "1.3.3",
3+
"version": "1.4.0-beta.0",
44
"homepage": "https://github.com/leancloud/javascript-sdk",
55
"authors": [
66
"LeanCloud <[email protected]>"

changelog.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# 1.4.0-beta.0 日期:2016 年 8 月 23 日
2+
* 支持 ES2015 的 extends 语法来声明 `AV.Object` 的子类,增加了 `AV.Object.register` 方法用于注册声明的子类。
3+
4+
```javascript
5+
class Article extends AV.Object {}
6+
AV.Object.register(Article);
7+
```
8+
9+
* `AV.Query` 支持查询 `AV.File`
10+
* 修复多次调用 `AV.Object.extend('ClassName')` 后可能导致堆栈溢出的问题
11+
* 修复 `AV.Query#addDescending` 没有返回 query 的问题,现在支持链式调用了
12+
* 修复 React Native 0.32 中找不到 `react-native` 模块的问题
13+
114
## 1.3.3 日期:2016 年 8 月 2 日
215
* 修复在 `AV.Object` 子类某属性的 getter 中调用 `AV.Object#get` 方法时调用栈溢出的问题
316

dist/av-es6.js

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5491,11 +5491,11 @@ module.exports = function(AV) {
54915491
AV.File = function(name, data, type) {
54925492

54935493
this.attributes = {
5494-
name: name,
5494+
name,
54955495
url: '',
54965496
metaData: {},
54975497
// 用来存储转换后要上传的 base64 String
5498-
base64: ''
5498+
base64: '',
54995499
};
55005500

55015501
let owner;
@@ -5504,8 +5504,12 @@ module.exports = function(AV) {
55045504
} else if (!AV._config.disableCurrentUser) {
55055505
try {
55065506
owner = AV.User.current();
5507-
} catch (e) {
5508-
console.warn('Get current user failed. It seems this runtime use an async storage system, please new AV.File in the callback of AV.User.currentAsync().');
5507+
} catch (error) {
5508+
if ('SYNC_API_NOT_AVAILABLE' === error.code) {
5509+
console.warn('Get current user failed. It seems this runtime use an async storage system, please create AV.File in the callback of AV.User.currentAsync().');
5510+
} else {
5511+
throw error;
5512+
}
55095513
}
55105514
}
55115515

@@ -5586,6 +5590,8 @@ module.exports = function(AV) {
55865590
};
55875591

55885592
AV.File.prototype = {
5593+
className: '_File',
5594+
55895595
toJSON: function() {
55905596
return AV._encode(this);
55915597
},
@@ -6318,7 +6324,9 @@ if (!localStorage.async) {
63186324
_(syncApiNames).each(function(apiName) {
63196325
if (typeof localStorage[apiName] !== 'function') {
63206326
localStorage[apiName] = function() {
6321-
throw new Error('Synchronous API [' + apiName + '] is not available in this runtime.');
6327+
const error = new Error('Synchronous API [' + apiName + '] is not available in this runtime.');
6328+
error.code = 'SYNC_API_NOT_AVAILABLE';
6329+
throw error;
63226330
};
63236331
}
63246332
});
@@ -7751,10 +7759,14 @@ module.exports = function(AV) {
77517759
// This new subclass has been told to extend both from "this" and from
77527760
// OldClassObject. This is multiple inheritance, which isn't supported.
77537761
// For now, let's just pick one.
7754-
NewClassObject = OldClassObject._extend(protoProps, classProps);
7762+
if (protoProps || classProps) {
7763+
NewClassObject = OldClassObject._extend(protoProps, classProps);
7764+
} else {
7765+
return OldClassObject;
7766+
}
77557767
} else {
77567768
protoProps = protoProps || {};
7757-
protoProps.className = className;
7769+
protoProps._className = className;
77587770
NewClassObject = this._extend(protoProps, classProps);
77597771
}
77607772
// Extending a subclass should reuse the classname automatically.
@@ -7772,6 +7784,29 @@ module.exports = function(AV) {
77727784
return NewClassObject;
77737785
};
77747786

7787+
// ES6 class syntax support
7788+
Object.defineProperty(AV.Object.prototype, 'className', {
7789+
get: function(){
7790+
const className = this._className || this.constructor.name;
7791+
// If someone tries to subclass "User", coerce it to the right type.
7792+
if (className === "User") {
7793+
return "_User";
7794+
}
7795+
return className;
7796+
},
7797+
});
7798+
7799+
AV.Object.register = klass => {
7800+
if (!(klass.prototype instanceof AV.Object)) {
7801+
throw new Error('registered class is not a subclass of AV.Object');
7802+
}
7803+
const className = klass.name;
7804+
if (!className.length) {
7805+
throw new Error('registered class must be named');
7806+
}
7807+
AV.Object._classMap[className] = klass;
7808+
};
7809+
77757810
AV.Object._findUnsavedChildren = function(object, children, files) {
77767811
AV._traverse(object, function(object) {
77777812
if (object instanceof AV.Object) {
@@ -9302,8 +9337,10 @@ module.exports = function(AV) {
93029337
var query = new AV.Query(response.className);
93039338
var results = _.map(response.results, function(json) {
93049339
var obj = query._newObject(response);
9305-
obj._finishFetch(query._processResult(json), true);
9306-
return obj;
9340+
if (obj._finishFetch) {
9341+
obj._finishFetch(query._processResult(json), true);
9342+
}
9343+
return obj;
93079344
});
93089345
return {
93099346
results: results,
@@ -9414,7 +9451,9 @@ module.exports = function(AV) {
94149451
return request.then(function(response) {
94159452
return _.map(response.results, function(json) {
94169453
var obj = self._newObject(response);
9417-
obj._finishFetch(self._processResult(json), true);
9454+
if (obj._finishFetch) {
9455+
obj._finishFetch(self._processResult(json), true);
9456+
}
94189457
return obj;
94199458
});
94209459
})._thenRunCallbacks(options);
@@ -9474,7 +9513,9 @@ module.exports = function(AV) {
94749513
return request.then(function(response) {
94759514
return _.map(response.results, function(json) {
94769515
var obj = self._newObject();
9477-
obj._finishFetch(self._processResult(json), true);
9516+
if (obj._finishFetch) {
9517+
obj._finishFetch(self._processResult(json), true);
9518+
}
94789519
return obj;
94799520
})[0];
94809521
})._thenRunCallbacks(options);
@@ -9881,7 +9922,7 @@ module.exports = function(AV) {
98819922
this._order += ',-' + key;
98829923
else
98839924
this._order = '-' + key;
9884-
return key;
9925+
return this;
98859926
},
98869927

98879928
/**
@@ -10212,7 +10253,7 @@ module.exports = function(AV) {
1021210253
**/
1021310254

1021410255
const request = require('superagent');
10215-
const debug = require('debug')('request');
10256+
const debug = require('debug')('leancloud:request');
1021610257
const md5 = require('md5');
1021710258
const AVPromise = require('./promise');
1021810259
const Cache = require('./cache');
@@ -10279,16 +10320,20 @@ const checkRouter = (router) => {
1027910320
}
1028010321
};
1028110322

10323+
let requestsCount = 0;
10324+
1028210325
const ajax = (method, resourceUrl, data, headers = {}, onprogress) => {
10283-
debug(method, resourceUrl, data, headers);
10326+
const count = requestsCount++;
10327+
10328+
debug(`request(${count})`, method, resourceUrl, data, headers);
1028410329

1028510330
const promise = new AVPromise();
1028610331
const req = request(method, resourceUrl)
1028710332
.set(headers)
1028810333
.send(data)
1028910334
.end((err, res) => {
1029010335
if (res) {
10291-
debug(res.status, res.body, res.text);
10336+
debug(`response(${count})`, res.status, res.body && res.text, res.header);
1029210337
}
1029310338
if (err) {
1029410339
if (res) {
@@ -11826,7 +11871,7 @@ module.exports = function(AV) {
1182611871
*/
1182711872
logIn: function(options) {
1182811873
var model = this;
11829-
var request = AVRequest("login", null, null, "GET", this.toJSON());
11874+
var request = AVRequest('login', null, null, 'POST', this.toJSON());
1183011875
return request.then(function(resp, status, xhr) {
1183111876
var serverAttrs = model.parse(resp, status, xhr);
1183211877
model._finishFetch(serverAttrs);
@@ -13165,7 +13210,7 @@ module.exports = {
1316513210
* Each engineer has a duty to keep the code elegant
1316613211
**/
1316713212

13168-
module.exports = 'js1.3.3';
13213+
module.exports = 'js1.4.0-beta.0';
1316913214

1317013215
},{}]},{},[28])(28)
1317113216
});

dist/av-min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/av.js

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5460,8 +5460,12 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
54605460
} else if (!AV._config.disableCurrentUser) {
54615461
try {
54625462
owner = AV.User.current();
5463-
} catch (e) {
5464-
console.warn('Get current user failed. It seems this runtime use an async storage system, please new AV.File in the callback of AV.User.currentAsync().');
5463+
} catch (error) {
5464+
if ('SYNC_API_NOT_AVAILABLE' === error.code) {
5465+
console.warn('Get current user failed. It seems this runtime use an async storage system, please create AV.File in the callback of AV.User.currentAsync().');
5466+
} else {
5467+
throw error;
5468+
}
54655469
}
54665470
}
54675471

@@ -5541,6 +5545,8 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
55415545
};
55425546

55435547
AV.File.prototype = {
5548+
className: '_File',
5549+
55445550
toJSON: function toJSON() {
55455551
return AV._encode(this);
55465552
},
@@ -6271,7 +6277,9 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
62716277
_(syncApiNames).each(function (apiName) {
62726278
if (typeof localStorage[apiName] !== 'function') {
62736279
localStorage[apiName] = function () {
6274-
throw new Error('Synchronous API [' + apiName + '] is not available in this runtime.');
6280+
var error = new Error('Synchronous API [' + apiName + '] is not available in this runtime.');
6281+
error.code = 'SYNC_API_NOT_AVAILABLE';
6282+
throw error;
62756283
};
62766284
}
62776285
});
@@ -7688,10 +7696,14 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
76887696
// This new subclass has been told to extend both from "this" and from
76897697
// OldClassObject. This is multiple inheritance, which isn't supported.
76907698
// For now, let's just pick one.
7691-
NewClassObject = OldClassObject._extend(protoProps, classProps);
7699+
if (protoProps || classProps) {
7700+
NewClassObject = OldClassObject._extend(protoProps, classProps);
7701+
} else {
7702+
return OldClassObject;
7703+
}
76927704
} else {
76937705
protoProps = protoProps || {};
7694-
protoProps.className = className;
7706+
protoProps._className = className;
76957707
NewClassObject = this._extend(protoProps, classProps);
76967708
}
76977709
// Extending a subclass should reuse the classname automatically.
@@ -7709,6 +7721,29 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
77097721
return NewClassObject;
77107722
};
77117723

7724+
// ES6 class syntax support
7725+
Object.defineProperty(AV.Object.prototype, 'className', {
7726+
get: function get() {
7727+
var className = this._className || this.constructor.name;
7728+
// If someone tries to subclass "User", coerce it to the right type.
7729+
if (className === "User") {
7730+
return "_User";
7731+
}
7732+
return className;
7733+
}
7734+
});
7735+
7736+
AV.Object.register = function (klass) {
7737+
if (!(klass.prototype instanceof AV.Object)) {
7738+
throw new Error('registered class is not a subclass of AV.Object');
7739+
}
7740+
var className = klass.name;
7741+
if (!className.length) {
7742+
throw new Error('registered class must be named');
7743+
}
7744+
AV.Object._classMap[className] = klass;
7745+
};
7746+
77127747
AV.Object._findUnsavedChildren = function (object, children, files) {
77137748
AV._traverse(object, function (object) {
77147749
if (object instanceof AV.Object) {
@@ -9216,7 +9251,9 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
92169251
var query = new AV.Query(response.className);
92179252
var results = _.map(response.results, function (json) {
92189253
var obj = query._newObject(response);
9219-
obj._finishFetch(query._processResult(json), true);
9254+
if (obj._finishFetch) {
9255+
obj._finishFetch(query._processResult(json), true);
9256+
}
92209257
return obj;
92219258
});
92229259
return {
@@ -9324,7 +9361,9 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
93249361
return request.then(function (response) {
93259362
return _.map(response.results, function (json) {
93269363
var obj = self._newObject(response);
9327-
obj._finishFetch(self._processResult(json), true);
9364+
if (obj._finishFetch) {
9365+
obj._finishFetch(self._processResult(json), true);
9366+
}
93289367
return obj;
93299368
});
93309369
})._thenRunCallbacks(options);
@@ -9384,7 +9423,9 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
93849423
return request.then(function (response) {
93859424
return _.map(response.results, function (json) {
93869425
var obj = self._newObject();
9387-
obj._finishFetch(self._processResult(json), true);
9426+
if (obj._finishFetch) {
9427+
obj._finishFetch(self._processResult(json), true);
9428+
}
93889429
return obj;
93899430
})[0];
93909431
})._thenRunCallbacks(options);
@@ -9786,7 +9827,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
97869827
*/
97879828
addDescending: function addDescending(key) {
97889829
if (this._order) this._order += ',-' + key;else this._order = '-' + key;
9789-
return key;
9830+
return this;
97909831
},
97919832

97929833
/**
@@ -10114,7 +10155,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1011410155
**/
1011510156

1011610157
var request = require('superagent');
10117-
var debug = require('debug')('request');
10158+
var debug = require('debug')('leancloud:request');
1011810159
var md5 = require('md5');
1011910160
var AVPromise = require('./promise');
1012010161
var Cache = require('./cache');
@@ -10148,16 +10189,20 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1014810189
}
1014910190
};
1015010191

10192+
var requestsCount = 0;
10193+
1015110194
var ajax = function ajax(method, resourceUrl, data) {
1015210195
var headers = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
1015310196
var onprogress = arguments[4];
1015410197

10155-
debug(method, resourceUrl, data, headers);
10198+
var count = requestsCount++;
10199+
10200+
debug("request(" + count + ")", method, resourceUrl, data, headers);
1015610201

1015710202
var promise = new AVPromise();
1015810203
var req = request(method, resourceUrl).set(headers).send(data).end(function (err, res) {
1015910204
if (res) {
10160-
debug(res.status, res.body, res.text);
10205+
debug("response(" + count + ")", res.status, res.body && res.text, res.header);
1016110206
}
1016210207
if (err) {
1016310208
if (res) {
@@ -11664,7 +11709,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1166411709
*/
1166511710
logIn: function logIn(options) {
1166611711
var model = this;
11667-
var request = AVRequest("login", null, null, "GET", this.toJSON());
11712+
var request = AVRequest('login', null, null, 'POST', this.toJSON());
1166811713
return request.then(function (resp, status, xhr) {
1166911714
var serverAttrs = model.parse(resp, status, xhr);
1167011715
model._finishFetch(serverAttrs);
@@ -12962,6 +13007,6 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
1296213007
* Each engineer has a duty to keep the code elegant
1296313008
**/
1296413009

12965-
module.exports = 'js1.3.3';
13010+
module.exports = 'js1.4.0-beta.0';
1296613011
}, {}] }, {}, [28])(28);
1296713012
});

0 commit comments

Comments
 (0)