Skip to content

Commit 0dcc442

Browse files
wangxiaoleeyeh
authored andcommitted
增加 AV._config.userAgent,补充 node demo 目录。 (#273)
* Clean code 修改 NPM 中 SDK 名字 修正 bower 发布名。 启用 ESlint,基于 Airbnb 编码规范 补充 Nodejs 开发目录 Supplementary README.md Add ESlint rules setting Do not compile demo/node directory Perfect the documents Replace AV._ajax to Requset in test case Deprecate AV._ajax Change UA by AV._config.userAgent Do not use new package name * Browser unit test import superagent. * Remove debug from devDependence. * Fixed some copywriting. * fixed av.file unit test in node 0.12.14. * fixed av.file unit test in node 0.12.14.
1 parent e4fd0c6 commit 0dcc442

File tree

12 files changed

+94
-38
lines changed

12 files changed

+94
-38
lines changed

.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
extends: 'airbnb',
3+
rules: {
4+
'no-param-reassign': 0,
5+
'no-underscore-dangle': 0
6+
}
7+
};

.jshintrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,30 @@ JavaScript SDK for [LeanCloud](http://leancloud.cn/).
1111

1212
可以使用以下命令安装 1.0.0-x 版本:`npm install avoscloud-sdk@next`
1313

14-
## 贡献
14+
## 贡献代码
1515

16-
* fork 这个项目
16+
* `fork` 这个项目
1717
* `npm install` 安装相关依赖
18-
* 浏览器环境执行 `gulp dev`,会自动启动 demo 目录,可在 test-es6.js 中修改和测试,test-es5.js 为自动生成的代码
19-
* 确保测试全部通过 `gulp test`,浏览器环境打开 test/test.html
20-
* 提交并发起 Pull Request
18+
* 开发和调试
19+
* 浏览器环境执行 `gulp dev`,会自动启动 `demo` 目录,可在 `test-es6.js` 中修改和测试,`test-es5.js` 为自动生成的代码
20+
* Nodejs 环境可以在 `demo/node` 目录中,通过执行 `node test.js` 使用 `test.js` 文件开发与调试。推荐安装 `node inspector` 来调试,安装后执行 `node-debug test.js`。每次修改代码后,如果开发代码引用的是 dist 目录中的代码,需要执行 `gulp release`
21+
* 确保测试全部通过 `gulp test`,浏览器环境打开 `test/test.html`
22+
* 提交并发起 `Pull Request`
2123
* 执行 `gulp release` 会生成全部版本的 SDK
2224

2325
项目的目录结构说明如下:
2426

2527
```
2628
├── README.md // 说明文档
27-
├── bower.json
29+
├── demo // demo 目录中有一些代码片段,主要用于开发与调试
2830
├── changelog.md
2931
├── dist // 编译之后生成的文件将会在此目录下
3032
│ ├── av-es6.js // 合并后的完整源码(ES6 版本)
3133
│ ├── av.js // 合并并编译后的完整源码(ES5 版本)
3234
│ ├── av-min.js // 合并、压缩并编译后的源码(ES5 版本)
3335
│ ├── node // 目录中为生成的 nodejs 版本代码
3436
│ └── ...
35-
├── gulpfile.js
37+
├── gulpfile.babel.js
3638
├── src
3739
│ ├── av.js // node.js 环境入口文件
3840
│ ├── browserify-wrapper // 目录中为针对 node.js 与浏览器环境之间差异的不同实现

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0-rc9.1",
44
"homepage": "https://github.com/leancloud/javascript-sdk",
55
"authors": [
6-
"killme2008 <xzhuang@leancloud.rocks>"
6+
"LeanCloud <support@leancloud.rocks>"
77
],
88
"description": "LeanCloud JavaScript SDK",
99
"main": "dist/av.js",

demo/node/test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Nodejs 4.x 版本已经支持 EcmaScript2015 (ES6)
2+
3+
const AV = require('../../dist/node/av');
4+
5+
// 初始化
6+
const appId = 'a5CDnmOX94uSth8foK9mjHfq-gzGzoHsz';
7+
const appKey = 'Ue3h6la9zH0IxkUJmyhLjk9h';
8+
9+
AV.init({ appId, appKey });
10+
11+
// 基本存储
12+
const TestClass = AV.Object.extend('TestClass');
13+
const testObj = new TestClass();
14+
testObj.set({
15+
name: 'hjiang',
16+
phone: '123123123',
17+
});
18+
19+
testObj.save().then(() => {
20+
console.log('success');
21+
}).catch((err) => {
22+
console.log('failed');
23+
console.log(err);
24+
});
25+
26+
// 存储文件
27+
const base64 = 'd29ya2luZyBhdCBhdm9zY2xvdWQgaXMgZ3JlYXQh';
28+
const file = new AV.File('myfile.txt', { base64 });
29+
file.metaData('format', 'txt file');
30+
file.save().then(() => {
31+
console.log('success');
32+
}).catch((error) => {
33+
console.log(error);
34+
});
35+
36+
// 查找文件
37+
const query = new AV.Query(TestClass);
38+
query.equalTo('name', 'hjiang');
39+
query.find().then(() => {
40+
console.log('success');
41+
});

demo/test-es5.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
// 初始化
44
var appId = 'a5CDnmOX94uSth8foK9mjHfq-gzGzoHsz';
55
var appKey = 'Ue3h6la9zH0IxkUJmyhLjk9h';
6-
AV.init({
7-
appId: appId,
8-
appKey: appKey
9-
});
6+
AV.init({ appId: appId, appKey: appKey });
107

118
// 基本存储
129
var TestClass = AV.Object.extend('TestClass');

demo/test-es6.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// 初始化
22
const appId = 'a5CDnmOX94uSth8foK9mjHfq-gzGzoHsz';
33
const appKey = 'Ue3h6la9zH0IxkUJmyhLjk9h';
4-
AV.init({
5-
appId: appId,
6-
appKey: appKey
7-
});
4+
AV.init({ appId, appKey });
85

96
// 基本存储
107
const TestClass = AV.Object.extend('TestClass');
@@ -38,4 +35,3 @@ query.find().then((list) => {
3835
console.log(list);
3936
});
4037

41-

gulpfile.babel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ gulp.task('clean-demo', () => {
144144

145145
// 编译 Demo 中的代码
146146
gulp.task('babel-demo', ['clean-demo'], () => {
147-
return gulp.src('demo/**/*.js')
147+
return gulp.src('demo/*.js')
148148
// .pipe(sourcemaps.init())
149149
.pipe(babel())
150150
.pipe(concat('test-es5.js'))

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
"babel-preset-es2015": "^6.3.13",
2424
"browser-sync": "^2.2.1",
2525
"browserify": "^11.0.1",
26+
"eslint": "^2.8.0",
27+
"eslint-config-airbnb": "^8.0.0",
28+
"eslint-plugin-import": "^1.6.0",
29+
"eslint-plugin-jsx-a11y": "^1.0.3",
30+
"eslint-plugin-react": "^5.0.1",
2631
"expect.js": "0.2.0",
2732
"gulp": "^3.8.10",
2833
"gulp-babel": "^6.1.1",

src/utils.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
* Each engineer has a duty to keep the code elegant
44
**/
55

6-
'use strict';
7-
86
const _ = require('underscore');
97
const ajax = require('./ajax');
108
const Cache = require('./cache');
119
const md5 = require('md5');
12-
const debug = require('debug')('utils');
1310

1411
// 计算 X-LC-Sign 的签名方法
1512
const sign = (key, isMasterKey) => {
@@ -30,7 +27,7 @@ const init = (AV) => {
3027
// 服务器请求的节点 host
3128
const API_HOST = {
3229
cn: 'https://api.leancloud.cn',
33-
us: 'https://us-api.leancloud.cn'
30+
us: 'https://us-api.leancloud.cn',
3431
};
3532

3633
_.extend(AVConfig, {
@@ -45,7 +42,10 @@ const init = (AV) => {
4542
isNode: false,
4643

4744
// 禁用 currentUser,通常用于多用户环境
48-
disableCurrentUser: false
45+
disableCurrentUser: false,
46+
47+
// Internal config can modifie the UserAgent
48+
userAgent: null,
4949
});
5050

5151
/**
@@ -338,7 +338,10 @@ const init = (AV) => {
338338
return new Date(Date.UTC(year, month, day, hour, minute, second, milli));
339339
};
340340

341-
AV._ajax = ajax;
341+
AV._ajax = (...args) => {
342+
console.warn('AV._ajax is deprecated, and will be removed in next release.');
343+
ajax(...args);
344+
};
342345

343346
// A self-propagating extend function.
344347
AV._extend = function(protoProps, classProps) {
@@ -470,7 +473,7 @@ const init = (AV) => {
470473
}
471474
}
472475

473-
return AV._ajax(method, apiURL, dataObject, headers).then(null, function(response) {
476+
return ajax(method, apiURL, dataObject, headers).then(null, function(response) {
474477
// Transform the error into an instance of AV.Error by trying to parse
475478
// the error string as JSON.
476479
var error;
@@ -747,4 +750,4 @@ const init = (AV) => {
747750
module.exports = {
748751

749752
init: init
750-
};
753+
};

0 commit comments

Comments
 (0)