Skip to content

Commit eaf018b

Browse files
refactor: code
1 parent 30aaab2 commit eaf018b

26 files changed

Lines changed: 267 additions & 252 deletions

DOCUMENTATION-v4.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ internally within the server.
10871087
module.exports = {
10881088
// ...
10891089
devServer: {
1090-
onAfterSetupMiddleware (devServer) {
1090+
onAfterSetupMiddleware(devServer) {
10911091
if (!devServer) {
10921092
throw new Error("webpack-dev-server is not defined");
10931093
}
@@ -1118,7 +1118,7 @@ example:
11181118
module.exports = {
11191119
// ...
11201120
devServer: {
1121-
onBeforeSetupMiddleware (devServer) {
1121+
onBeforeSetupMiddleware(devServer) {
11221122
if (!devServer) {
11231123
throw new Error("webpack-dev-server is not defined");
11241124
}
@@ -1147,12 +1147,12 @@ Provides the ability to execute a custom function when webpack-dev-server starts
11471147
module.exports = {
11481148
// ...
11491149
devServer: {
1150-
onListening (devServer) {
1150+
onListening(devServer) {
11511151
if (!devServer) {
11521152
throw new Error("webpack-dev-server is not defined");
11531153
}
11541154

1155-
const {port} = devServer.server.address();
1155+
const { port } = devServer.server.address();
11561156
console.log("Listening on port:", port);
11571157
},
11581158
},
@@ -1394,7 +1394,7 @@ module.exports = {
13941394
proxy: {
13951395
"/api": {
13961396
target: "http://localhost:3000",
1397-
bypass (req, res, proxyOptions) {
1397+
bypass(req, res, proxyOptions) {
13981398
if (req.headers.accept.includes("html")) {
13991399
console.log("Skipping proxy for browser request.");
14001400
return "/index.html";

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,16 @@ If you use TypeScript in the webpack config, you'll need to properly type `devSe
229229

230230
```ts
231231
/// <reference path="node_modules/webpack-dev-server/types/lib/Server.d.ts"/>
232-
import { type Configuration } from "webpack";
232+
import { type Configuration } from "webpack";
233233

234234
// Your logic
235235
```
236236

237237
Or you can import the type from `webpack-dev-server`, i.e.
238238

239239
```ts
240-
import { type Configuration } from "webpack";
241-
import { type Configuration as DevServerConfiguration } from "webpack-dev-server";
240+
import { type Configuration } from "webpack";
241+
import { type Configuration as DevServerConfiguration } from "webpack-dev-server";
242242

243243
const devServer: DevServerConfiguration = {};
244244
const config: Configuration = { devServer };

client-src/clients/SockJSClient.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import SockJS from "../modules/sockjs-client/index.js";
22
import { log } from "../utils/log.js";
33

4+
/** @typedef {import("../index").EXPECTED_ANY} EXPECTED_ANY */
5+
46
export default class SockJSClient {
57
/**
6-
* @param {string} url
8+
* @param {string} url url
79
*/
810
constructor(url) {
911
// SockJS requires `http` and `https` protocols
@@ -12,38 +14,38 @@ export default class SockJSClient {
1214
);
1315
this.sock.onerror =
1416
/**
15-
* @param {Error} error
17+
* @param {Error} error error
1618
*/
1719
(error) => {
1820
log.error(error);
1921
};
2022
}
2123

2224
/**
23-
* @param {(...args: any[]) => void} f
25+
* @param {(...args: EXPECTED_ANY[]) => void} fn function
2426
*/
25-
onOpen(f) {
26-
this.sock.onopen = f;
27+
onOpen(fn) {
28+
this.sock.onopen = fn;
2729
}
2830

2931
/**
30-
* @param {(...args: any[]) => void} f
32+
* @param {(...args: EXPECTED_ANY[]) => void} fn function
3133
*/
32-
onClose(f) {
33-
this.sock.onclose = f;
34+
onClose(fn) {
35+
this.sock.onclose = fn;
3436
}
3537

3638
// call f with the message string as the first argument
3739
/**
38-
* @param {(...args: any[]) => void} f
40+
* @param {(...args: EXPECTED_ANY[]) => void} fn function
3941
*/
40-
onMessage(f) {
42+
onMessage(fn) {
4143
this.sock.onmessage =
4244
/**
43-
* @param {Error & { data: string }} e
45+
* @param {Error & { data: string }} err error
4446
*/
45-
(e) => {
46-
f(e.data);
47+
(err) => {
48+
fn(err.data);
4749
};
4850
}
4951
}
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { log } from "../utils/log.js";
22

3+
/** @typedef {import("../index").EXPECTED_ANY} EXPECTED_ANY */
4+
35
export default class WebSocketClient {
46
/**
5-
* @param {string} url
7+
* @param {string} url url to connect
68
*/
79
constructor(url) {
810
this.client = new WebSocket(url);
@@ -12,26 +14,26 @@ export default class WebSocketClient {
1214
}
1315

1416
/**
15-
* @param {(...args: any[]) => void} f
17+
* @param {(...args: EXPECTED_ANY[]) => void} fn function
1618
*/
17-
onOpen(f) {
18-
this.client.onopen = f;
19+
onOpen(fn) {
20+
this.client.onopen = fn;
1921
}
2022

2123
/**
22-
* @param {(...args: any[]) => void} f
24+
* @param {(...args: EXPECTED_ANY[]) => void} fn function
2325
*/
24-
onClose(f) {
25-
this.client.onclose = f;
26+
onClose(fn) {
27+
this.client.onclose = fn;
2628
}
2729

2830
// call f with the message string as the first argument
2931
/**
30-
* @param {(...args: any[]) => void} f
32+
* @param {(...args: EXPECTED_ANY[]) => void} fn function
3133
*/
32-
onMessage(f) {
33-
this.client.onmessage = (e) => {
34-
f(e.data);
34+
onMessage(fn) {
35+
this.client.onmessage = (err) => {
36+
fn(err.data);
3537
};
3638
}
3739
}

0 commit comments

Comments
 (0)