Skip to content

Commit f961b13

Browse files
committed
feature(fileop) class-properties, private methods
1 parent da528a6 commit f961b13

File tree

5 files changed

+27
-28
lines changed

5 files changed

+27
-28
lines changed

.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"plugins": [
3+
"@babel/plugin-proposal-private-methods",
4+
"@babel/plugin-proposal-class-properties"
5+
],
26
"env": {
37
"test": {
48
"plugins": [

client/fileop.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class Fileop extends Emitify {
3838
path: socketPath,
3939
});
4040

41-
this._setListeners(socket);
42-
this.operate = promisify(this._operate);
41+
this.#setListeners(socket);
42+
this.operate = promisify(this.#operate);
4343
this.socket = socket;
4444
}
4545

@@ -67,7 +67,7 @@ class Fileop extends Emitify {
6767
return this.operate('remove', from, files);
6868
}
6969

70-
_operate(name, from, to, files, fn = files) {
70+
#operate(name, from, to, files, fn = files) {
7171
const {socket} = this;
7272

7373
socket.emit('operation', name, from, to, files);
@@ -76,7 +76,7 @@ class Fileop extends Emitify {
7676
});
7777
}
7878

79-
_setListeners(socket) {
79+
#setListeners(socket) {
8080
this.on('auth', (username, password) => {
8181
socket.emit('auth', username, password);
8282
});

client/operator.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,35 @@ class FileOperator extends Emitify {
1313
this.socket = socket;
1414
this.id = id;
1515

16-
this._onError = this._onError.bind(this);
17-
this._onFile = this._onFile.bind(this);
18-
this._onProgress = this._onProgress.bind(this);
19-
this._onEnd = this._onEnd.bind(this);
20-
21-
socket.on(`${id}#error`, this._onError);
22-
socket.on(`${id}#file`, this._onFile);
23-
socket.on(`${id}#progress`, this._onProgress);
24-
socket.on(`${id}#end`, this._onEnd);
16+
socket.on(`${id}#error`, this.#onError);
17+
socket.on(`${id}#file`, this.#onFile);
18+
socket.on(`${id}#progress`, this.#onProgress);
19+
socket.on(`${id}#end`, this.#onEnd);
2520

2621
setTimeout(() => {
2722
socket.emit(`${id}#start`);
2823
}, 0);
2924
}
3025

31-
_onError(error) {
26+
#onError = (error) => {
3227
this.emit('error', error);
3328
}
3429

35-
_onFile(name) {
30+
#onFile = (name) => {
3631
this.emit('file', name);
3732
}
3833

39-
_onProgress(percent) {
34+
#onProgress = (percent) => {
4035
this.emit('progress', percent);
4136
}
4237

43-
_onEnd() {
38+
#onEnd = () => {
4439
const {id, socket} = this;
4540

46-
socket.off(`${id}#error`, this._onError);
47-
socket.off(`${id}#file`, this._onFile);
48-
socket.off(`${id}#progress`, this._onProgress);
49-
socket.off(`${id}#end`, this._onEnd);
41+
socket.off(`${id}#error`, this.#onError);
42+
socket.off(`${id}#file`, this.#onFile);
43+
socket.off(`${id}#progress`, this.#onProgress);
44+
socket.off(`${id}#end`, this.#onEnd);
5045

5146
this.emit('end');
5247
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
"devDependencies": {
6060
"@babel/cli": "^7.0.0",
6161
"@babel/core": "^7.0.0",
62+
"@babel/plugin-proposal-class-properties": "^7.3.0",
63+
"@babel/plugin-proposal-private-methods": "^7.3.0",
6264
"@babel/preset-env": "^7.0.0",
6365
"@babel/register": "^7.0.0",
6466
"babel-eslint": "^10.0.0",

webpack.config.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ const devtool = isDev ? 'eval' : 'source-map';
1212
const notEmpty = (a) => a;
1313
const clean = (array) => array.filter(notEmpty);
1414

15-
const rules = clean([
16-
!isDev && {
17-
test: /\.js$/,
18-
exclude: /node_modules/,
19-
loader: 'babel-loader',
20-
}
21-
]);
15+
const rules = [{
16+
test: /\.js$/,
17+
exclude: /node_modules/,
18+
loader: 'babel-loader',
19+
}];
2220

2321
module.exports = {
2422
devtool,

0 commit comments

Comments
 (0)