Skip to content

Commit 6be94b6

Browse files
author
Hovhannes Babayan
committed
improved promise polyfill usage under node.js
1 parent 5e1138d commit 6be94b6

9 files changed

Lines changed: 64 additions & 70 deletions

File tree

dist/attask.js

Lines changed: 52 additions & 45 deletions
Large diffs are not rendered by default.

examples/node/create-new-project.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
global.Promise = require('promise');
2-
31
var ApiFactory = require('./../../').ApiFactory;
42
var util = require('util');
53

examples/node/get-project-details.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
global.Promise = require('promise');
2-
31
var ApiFactory = require('./../../').ApiFactory;
42
var util = require('util');
53

examples/node/login.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
global.Promise = require('promise');
2-
31
var ApiFactory = require('./../../').ApiFactory;
42
var util = require('util');
53

examples/node/logout.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
global.Promise = require('promise');
2-
31
var ApiFactory = require('./../../').ApiFactory;
42
var util = require('util');
53

examples/node/search-for-projects.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
global.Promise = require('promise');
2-
31
var ApiFactory = require('./../../').ApiFactory;
42
var util = require('util');
53

gulpfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ gulp.task('build', ['clean-build'], function() {
3737
standalone: 'AtTask'
3838
}
3939
)
40+
.ignore('promise/polyfill')
4041
.bundle()
4142
.pipe(source('attask.js'))
4243
.pipe(gulp.dest(BUILD_DIR));

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require('promise/polyfill');
2+
13
var ApiFactory = require('./src/ApiFactory');
24
var Api = require('./src/Api');
35
var ApiUtil = require('./src/ApiUtil');

src/request.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,10 @@ module.exports = function(Api) {
1616
options.path = path_module.join(this.httpOptions.path, path);
1717

1818
if (fields.length !== 0) {
19-
params["fields"] = fields.join();
19+
params['fields'] = fields.join();
2020
}
2121
options.path += '?' + queryString.stringify(params);
2222

23-
// Add xsrf header
24-
//var xsrfValue = urlIsSameOrigin(config.url)
25-
// ? cookies.read(config.xsrfCookieName || defaults.xsrfCookieName)
26-
// : undefined;
27-
//if (xsrfValue) {
28-
// headers[config.xsrfHeaderName || defaults.xsrfHeaderName] = xsrfValue;
29-
//}
30-
3123
return new Promise(function (resolve, reject) {
3224
/*options = {
3325
hostname: 'echo.jsontest.com',
@@ -36,13 +28,15 @@ module.exports = function(Api) {
3628
withCredentials: false
3729
};*/
3830

39-
var req = http.request(options, function (res) {
31+
var request = http.request(options, function (response) {
4032
var body = '';
41-
//res.setEncoding('utf8');
42-
res.on('data', function (chunk) {
33+
if (typeof response.setEncoding === 'function') {
34+
response.setEncoding('utf8');
35+
}
36+
response.on('data', function (chunk) {
4337
body += chunk;
4438
});
45-
res.on('end', function () {
39+
response.on('end', function () {
4640
var data = JSON.parse(body);
4741
if (data.error) {
4842
reject(data);
@@ -51,8 +45,8 @@ module.exports = function(Api) {
5145
}
5246
});
5347
});
54-
req.on('error', reject);
55-
req.end();
48+
request.on('error', reject);
49+
request.end();
5650
});
5751
};
5852
};

0 commit comments

Comments
 (0)