Skip to content

Commit 5791223

Browse files
ESLint: lib
1 parent 316754f commit 5791223

File tree

6 files changed

+256
-242
lines changed

6 files changed

+256
-242
lines changed

.eslintignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
/lib/*.js
21
/tests_integration/*.js
32
/deps/**/*.js

.eslintrc.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"airbnb-base"
1010
],
1111
"rules": {
12-
"indent": ["error", 4]
12+
"indent": ["error", 4],
13+
"no-console": ["error", { "allow": ["info", "warn", "error"] }],
14+
"no-multi-assign": 0
1315
}
1416
}

lib/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module.exports = require('./zookeeper');
2-
module.exports.ZooKeeper = module.exports; // for backwards compatibility
2+
3+
module.exports.ZooKeeper = module.exports; // for backwards compatibility
34
module.exports.Promise = require('./zk_promise');

lib/zk_promise.js

+84-84
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,89 @@
1-
const ZooKeeper = require("./zookeeper");
1+
// needed to not break the interface
2+
/* eslint-disable camelcase */
3+
const ZooKeeper = require('./zookeeper');
24

35
class ZooKeeperPromise extends ZooKeeper {
4-
on_connected() {
5-
return new Promise((resolve) => {
6-
this.once('connect', () => {
7-
return resolve(this);
8-
});
9-
})
10-
}
11-
12-
create() {
13-
return this._promisify(super.a_create, arguments);
14-
}
15-
16-
exists() {
17-
return this._promisify(super.a_exists, arguments);
18-
}
19-
20-
w_exists() {
21-
return this._promisify(super.aw_exists, arguments);
22-
}
23-
24-
get() {
25-
return this._promisify(super.a_get, arguments);
26-
}
27-
28-
w_get() {
29-
return this._promisify(super.aw_get, arguments);
30-
}
31-
32-
get_children() {
33-
return this._promisify(super.a_get_children, arguments);
34-
}
35-
36-
w_get_children() {
37-
return this._promisify(super.aw_get_children, arguments);
38-
}
39-
40-
get_children2() {
41-
return this._promisify(super.a_get_children2, arguments);
42-
}
43-
44-
w_get_children2() {
45-
return this._promisify(super.aw_get_children2, arguments);
46-
}
47-
48-
set() {
49-
return this._promisify(super.a_set, arguments);
50-
}
51-
52-
delete_() {
53-
return this._promisify(super.delete_, arguments);
54-
}
55-
56-
get_acl() {
57-
return this._promisify(super.a_get_acl, arguments);
58-
}
59-
60-
set_acl() {
61-
return this._promisify(super.a_set_acl, arguments);
62-
}
63-
64-
sync() {
65-
return this._promisify(super.a_sync, arguments);
66-
}
67-
68-
_promisify(fn, args) {
69-
return new Promise((resolve, reject) => {
70-
const callback = (rc, error, result) => {
71-
if (rc) {
72-
reject(rc);
73-
} else {
74-
if (args.length > 3) {
75-
// if there are multiple success values, we return an array
76-
Array.prototype.shift.call(args, 1);
77-
Array.prototype.shift.call(args, 1);
78-
resolve(args);
79-
} else {
80-
resolve(result);
81-
}
82-
}
83-
};
84-
fn.apply(this, [...args, callback])
85-
});
86-
}
6+
on_connected() {
7+
return new Promise((resolve) => {
8+
this.once('connect', () => resolve(this));
9+
});
10+
}
11+
12+
create(...args) {
13+
return this.promisify(super.a_create, args);
14+
}
15+
16+
exists(...args) {
17+
return this.promisify(super.a_exists, args);
18+
}
19+
20+
w_exists(...args) {
21+
return this.promisify(super.aw_exists, args);
22+
}
23+
24+
get(...args) {
25+
return this.promisify(super.a_get, args);
26+
}
27+
28+
w_get(...args) {
29+
return this.promisify(super.aw_get, args);
30+
}
31+
32+
get_children(...args) {
33+
return this.promisify(super.a_get_children, args);
34+
}
35+
36+
w_get_children(...args) {
37+
return this.promisify(super.aw_get_children, args);
38+
}
39+
40+
get_children2(...args) {
41+
return this.promisify(super.a_get_children2, args);
42+
}
43+
44+
w_get_children2(...args) {
45+
return this.promisify(super.aw_get_children2, args);
46+
}
47+
48+
set(...args) {
49+
return this.promisify(super.a_set, args);
50+
}
51+
52+
// eslint-disable-next-line no-underscore-dangle
53+
delete_(...args) {
54+
// eslint-disable-next-line no-underscore-dangle
55+
return this.promisify(super.delete_, args);
56+
}
57+
58+
get_acl(...args) {
59+
return this.promisify(super.a_get_acl, args);
60+
}
61+
62+
set_acl(...args) {
63+
return this.promisify(super.a_set_acl, args);
64+
}
65+
66+
sync(...args) {
67+
return this.promisify(super.a_sync, args);
68+
}
69+
70+
promisify(fn, args) {
71+
return new Promise((resolve, reject) => {
72+
const callback = (rc, error, result) => {
73+
if (rc) {
74+
reject(rc);
75+
} else if (args.length > 3) {
76+
// if there are multiple success values, we return an array
77+
Array.prototype.shift.call(args, 1);
78+
Array.prototype.shift.call(args, 1);
79+
resolve(args);
80+
} else {
81+
resolve(result);
82+
}
83+
};
84+
fn.bind(this)(...args, callback);
85+
});
86+
}
8787
}
8888

8989
exports = module.exports = ZooKeeperPromise;

0 commit comments

Comments
 (0)