webpack-dev-service 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/cjs/client.cjs +111 -109
- package/client/cjs/events.cjs +33 -32
- package/client/cjs/hot.cjs +61 -60
- package/client/cjs/index.cjs +10 -8
- package/client/cjs/main.cjs +63 -60
- package/client/cjs/ui/overlay.cjs +64 -63
- package/client/cjs/ui/progress.cjs +35 -35
- package/client/cjs/ui/utils/ansi/index.cjs +439 -413
- package/client/cjs/ui/utils/ansi/regx.cjs +8 -8
- package/client/cjs/ui/utils/ansi/utils.cjs +14 -14
- package/client/cjs/ui/utils/index.cjs +99 -99
- package/client/esm/client.js +111 -109
- package/client/esm/events.js +33 -32
- package/client/esm/hot.js +61 -60
- package/client/esm/index.js +8 -8
- package/client/esm/main.js +63 -60
- package/client/esm/ui/overlay.js +64 -63
- package/client/esm/ui/progress.js +35 -35
- package/client/esm/ui/utils/ansi/index.js +439 -413
- package/client/esm/ui/utils/ansi/regx.js +8 -8
- package/client/esm/ui/utils/ansi/utils.js +14 -14
- package/client/esm/ui/utils/index.js +99 -99
- package/package.json +11 -11
- package/server/cjs/dev.cjs +30 -36
- package/server/cjs/hot.cjs +174 -177
- package/server/cjs/index.cjs +16 -17
- package/server/esm/dev.js +28 -32
- package/server/esm/hot.js +171 -172
- package/server/esm/index.js +14 -13
- package/types/client/client.d.ts +7 -7
- package/types/client/events.d.ts +10 -10
- package/types/client/message.d.ts +25 -25
- package/types/client/ui/overlay.d.ts +12 -12
- package/types/client/ui/progress.d.ts +8 -8
- package/types/client/ui/utils/ansi/enum.d.ts +7 -7
- package/types/client/ui/utils/ansi/index.d.ts +11 -11
- package/types/client/ui/utils/ansi/interface.d.ts +46 -42
- package/types/server/dev.d.ts +4 -4
- package/types/server/hot.d.ts +5 -5
- package/types/server/index.d.ts +2 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
* @package webpack-dev-service
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @version 0.5.4
|
|
5
|
+
* @author nuintun <nuintun@qq.com>
|
|
6
|
+
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
+
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
* @package webpack-dev-service
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @version 0.5.4
|
|
5
|
+
* @author nuintun <nuintun@qq.com>
|
|
6
|
+
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
+
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @module utils
|
|
14
14
|
*/
|
|
15
15
|
function toUint8(uint8) {
|
|
16
|
-
|
|
16
|
+
return uint8 & 0xff;
|
|
17
17
|
}
|
|
18
18
|
function getThemeColor(defaultColor, color) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
if (color) {
|
|
20
|
+
const [r, g, b] = color;
|
|
21
|
+
return [toUint8(r), toUint8(g), toUint8(b)];
|
|
22
|
+
}
|
|
23
|
+
return defaultColor;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
exports.getThemeColor = getThemeColor;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
* @package webpack-dev-service
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @version 0.5.4
|
|
5
|
+
* @author nuintun <nuintun@qq.com>
|
|
6
|
+
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
+
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
12
|
const index = require('./ansi/index.cjs');
|
|
@@ -17,106 +17,106 @@ const index = require('./ansi/index.cjs');
|
|
|
17
17
|
const ansi = new index();
|
|
18
18
|
const defaultStyleElement = document.createElement('style');
|
|
19
19
|
function injectCSS(css, styleElement = defaultStyleElement) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const { head } = document;
|
|
21
|
+
styleElement.appendChild(document.createTextNode(css.trim()));
|
|
22
|
+
if (!head.contains(styleElement)) {
|
|
23
|
+
head.appendChild(styleElement);
|
|
24
|
+
}
|
|
25
|
+
return styleElement;
|
|
26
26
|
}
|
|
27
27
|
function appendHTML(html, parent) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
const nodes = [];
|
|
29
|
+
const parser = new DOMParser();
|
|
30
|
+
const stage = parent || document.body;
|
|
31
|
+
const fragment = document.createDocumentFragment();
|
|
32
|
+
const { body } = parser.parseFromString(html.trim(), 'text/html');
|
|
33
|
+
while (body.firstChild) {
|
|
34
|
+
nodes.push(fragment.appendChild(body.firstChild));
|
|
35
|
+
}
|
|
36
|
+
stage.appendChild(fragment);
|
|
37
|
+
return nodes;
|
|
38
38
|
}
|
|
39
39
|
function escapeHTML(text) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
return text.replace(/[&<>"']/gm, match => {
|
|
41
|
+
switch (match) {
|
|
42
|
+
case '&':
|
|
43
|
+
return '&';
|
|
44
|
+
case '<':
|
|
45
|
+
return '<';
|
|
46
|
+
case '>':
|
|
47
|
+
return '>';
|
|
48
|
+
case '"':
|
|
49
|
+
return '"';
|
|
50
|
+
case "'":
|
|
51
|
+
return ''';
|
|
52
|
+
default:
|
|
53
|
+
return match;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
56
|
}
|
|
57
57
|
function blockToHTML({ style, value, url }) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
58
|
+
const styles = [];
|
|
59
|
+
const textDecorations = [];
|
|
60
|
+
if (style.dim) {
|
|
61
|
+
styles.push(`opacity:0.5`);
|
|
62
|
+
}
|
|
63
|
+
if (style.bold) {
|
|
64
|
+
styles.push(`font-weight:bold`);
|
|
65
|
+
}
|
|
66
|
+
if (style.italic) {
|
|
67
|
+
styles.push(`font-style:italic`);
|
|
68
|
+
}
|
|
69
|
+
if (style.inverse) {
|
|
70
|
+
styles.push(`filter:invert(1)`);
|
|
71
|
+
}
|
|
72
|
+
if (style.hidden) {
|
|
73
|
+
styles.push(`visibility:hidden`);
|
|
74
|
+
}
|
|
75
|
+
if (style.blink) {
|
|
76
|
+
textDecorations.push('blink');
|
|
77
|
+
}
|
|
78
|
+
if (style.overline) {
|
|
79
|
+
textDecorations.push('overline');
|
|
80
|
+
}
|
|
81
|
+
if (style.underline) {
|
|
82
|
+
textDecorations.push('underline');
|
|
83
|
+
}
|
|
84
|
+
if (style.strikethrough) {
|
|
85
|
+
textDecorations.push('line-through');
|
|
86
|
+
}
|
|
87
|
+
const { color, background } = style;
|
|
88
|
+
if (color) {
|
|
89
|
+
styles.push(`color:rgb(${color})`);
|
|
90
|
+
}
|
|
91
|
+
if (background) {
|
|
92
|
+
styles.push(`background-color:rgb(${background})`);
|
|
93
|
+
}
|
|
94
|
+
if (textDecorations.length > 0) {
|
|
95
|
+
styles.push(`text-decoration:${textDecorations.join(' ')}`);
|
|
96
|
+
}
|
|
97
|
+
const escapedValue = escapeHTML(value);
|
|
98
|
+
const href = url ? JSON.stringify(escapeHTML(url)) : null;
|
|
99
|
+
if (styles.length <= 0) {
|
|
100
|
+
if (!href) {
|
|
101
|
+
return escapedValue;
|
|
102
|
+
}
|
|
103
|
+
return `<a href=${href} target="_blank">${escapedValue}</a>`;
|
|
104
|
+
}
|
|
105
|
+
const inlineStyle = JSON.stringify(`${styles.join(';')};`);
|
|
100
106
|
if (!href) {
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
return `<a href=${href} target="_blank">${escapedValue}</a>`;
|
|
104
|
-
}
|
|
105
|
-
const inlineStyle = JSON.stringify(`${styles.join(';')};`);
|
|
106
|
-
if (!href) {
|
|
107
|
-
return `<span style=${inlineStyle}>${escapedValue}</span>`;
|
|
108
|
-
}
|
|
109
|
-
return `<a style=${inlineStyle} href=${href} target="_blank">${escapedValue}</a>`;
|
|
107
|
+
return `<span style=${inlineStyle}>${escapedValue}</span>`;
|
|
108
|
+
}
|
|
109
|
+
return `<a style=${inlineStyle} href=${href} target="_blank">${escapedValue}</a>`;
|
|
110
110
|
}
|
|
111
111
|
function ansiToHTML(text) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
112
|
+
let html = '';
|
|
113
|
+
ansi.write(text, block => {
|
|
114
|
+
html += blockToHTML(block);
|
|
115
|
+
});
|
|
116
|
+
ansi.flush(block => {
|
|
117
|
+
html += blockToHTML(block);
|
|
118
|
+
});
|
|
119
|
+
return html;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
exports.ansiToHTML = ansiToHTML;
|
package/client/esm/client.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
* @package webpack-dev-service
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @version 0.5.4
|
|
5
|
+
* @author nuintun <nuintun@qq.com>
|
|
6
|
+
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
+
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
10
|
import { emit } from './events.js';
|
|
11
11
|
import Overlay from './ui/overlay.js';
|
|
12
12
|
import Progress from './ui/progress.js';
|
|
@@ -16,111 +16,113 @@ import { applyUpdate, setHash } from './hot.js';
|
|
|
16
16
|
* @module client
|
|
17
17
|
*/
|
|
18
18
|
function createClient(options) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const onHash = ({ hash }) => {
|
|
50
|
-
setHash(hash);
|
|
51
|
-
};
|
|
52
|
-
const setProblems = (type, problems) => {
|
|
53
|
-
const maps = {
|
|
54
|
-
errors: ['Error', 'error'],
|
|
55
|
-
warnings: ['Warning', 'warn']
|
|
19
|
+
let updateTimer;
|
|
20
|
+
const UPDATE_DELAY = 128;
|
|
21
|
+
const RETRY_INTERVAL = 3000;
|
|
22
|
+
const progress = new Progress();
|
|
23
|
+
const overlay = new Overlay(options.name);
|
|
24
|
+
const fallback = (error) => {
|
|
25
|
+
if (options.live) {
|
|
26
|
+
self.location.reload();
|
|
27
|
+
}
|
|
28
|
+
else if (error) {
|
|
29
|
+
console.error(error);
|
|
30
|
+
console.warn('Use fallback update but you turn off live reload, please reload by yourself.');
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const applyUpdateAsync = () => {
|
|
34
|
+
updateTimer = self.setTimeout(() => {
|
|
35
|
+
applyUpdate(options.hmr, fallback);
|
|
36
|
+
}, UPDATE_DELAY);
|
|
37
|
+
};
|
|
38
|
+
const onInvalid = () => {
|
|
39
|
+
clearTimeout(updateTimer);
|
|
40
|
+
if (options.progress) {
|
|
41
|
+
progress.update(0);
|
|
42
|
+
progress.show();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const onProgress = ({ value }) => {
|
|
46
|
+
if (options.progress) {
|
|
47
|
+
progress.update(value);
|
|
48
|
+
}
|
|
56
49
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
case 'invalid':
|
|
97
|
-
onInvalid();
|
|
98
|
-
break;
|
|
99
|
-
case 'progress':
|
|
100
|
-
onProgress(payload);
|
|
101
|
-
break;
|
|
102
|
-
case 'hash':
|
|
103
|
-
onHash(payload);
|
|
104
|
-
break;
|
|
105
|
-
case 'problems':
|
|
106
|
-
onProblems(payload);
|
|
107
|
-
break;
|
|
108
|
-
case 'ok':
|
|
109
|
-
onSuccess();
|
|
110
|
-
break;
|
|
50
|
+
const onHash = ({ hash }) => {
|
|
51
|
+
setHash(hash);
|
|
52
|
+
};
|
|
53
|
+
const setProblems = (type, problems) => {
|
|
54
|
+
const maps = {
|
|
55
|
+
errors: ['Error', 'error'],
|
|
56
|
+
warnings: ['Warning', 'warn']
|
|
57
|
+
};
|
|
58
|
+
if (options.overlay) {
|
|
59
|
+
overlay.setProblems(type, problems);
|
|
60
|
+
}
|
|
61
|
+
const [name, method] = maps[type];
|
|
62
|
+
const debug = console[method];
|
|
63
|
+
for (const { moduleName, message } of problems) {
|
|
64
|
+
debug(`\x1b[0m${name} in ${moduleName}\r\n\x1b[0m${message}`);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const onProblems = ({ errors, warnings }) => {
|
|
68
|
+
progress.hide();
|
|
69
|
+
setProblems('errors', errors);
|
|
70
|
+
setProblems('warnings', warnings);
|
|
71
|
+
if (options.overlay) {
|
|
72
|
+
overlay.show();
|
|
73
|
+
}
|
|
74
|
+
if (errors.length <= 0) {
|
|
75
|
+
applyUpdateAsync();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const onSuccess = () => {
|
|
79
|
+
overlay.hide();
|
|
80
|
+
progress.hide();
|
|
81
|
+
applyUpdateAsync();
|
|
82
|
+
};
|
|
83
|
+
const parseMessage = (message) => {
|
|
84
|
+
try {
|
|
85
|
+
return JSON.parse(message.data);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return null;
|
|
111
89
|
}
|
|
112
|
-
emit(action, payload, options);
|
|
113
|
-
}
|
|
114
90
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
91
|
+
const createWebSocket = (url) => {
|
|
92
|
+
const ws = new WebSocket(url);
|
|
93
|
+
ws.onmessage = (message) => {
|
|
94
|
+
const parsed = parseMessage(message);
|
|
95
|
+
if (parsed) {
|
|
96
|
+
const { action, payload } = parsed;
|
|
97
|
+
switch (action) {
|
|
98
|
+
case 'invalid':
|
|
99
|
+
onInvalid();
|
|
100
|
+
break;
|
|
101
|
+
case 'progress':
|
|
102
|
+
onProgress(payload);
|
|
103
|
+
break;
|
|
104
|
+
case 'hash':
|
|
105
|
+
onHash(payload);
|
|
106
|
+
break;
|
|
107
|
+
case 'problems':
|
|
108
|
+
onProblems(payload);
|
|
109
|
+
break;
|
|
110
|
+
case 'ok':
|
|
111
|
+
onSuccess();
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
emit(action, payload, options);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
ws.onclose = () => {
|
|
118
|
+
overlay.hide();
|
|
119
|
+
progress.hide();
|
|
120
|
+
setTimeout(() => {
|
|
121
|
+
createWebSocket(url);
|
|
122
|
+
}, RETRY_INTERVAL);
|
|
123
|
+
};
|
|
121
124
|
};
|
|
122
|
-
|
|
123
|
-
createWebSocket(`${options.origin}${options.path}`);
|
|
125
|
+
createWebSocket(`${options.origin}${options.path}`);
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
export { createClient as default };
|
package/client/esm/events.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
* @package webpack-dev-service
|
|
3
|
+
* @license MIT
|
|
4
|
+
* @version 0.5.4
|
|
5
|
+
* @author nuintun <nuintun@qq.com>
|
|
6
|
+
* @description A koa 2 middleware for webpack development and hot reloading.
|
|
7
|
+
* @see https://github.com/nuintun/webpack-dev-service#readme
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
10
|
/**
|
|
11
11
|
* @module events
|
|
12
12
|
*/
|
|
13
13
|
const events = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
ok: [],
|
|
15
|
+
hash: [],
|
|
16
|
+
invalid: [],
|
|
17
|
+
problems: [],
|
|
18
|
+
progress: []
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* @function on
|
|
@@ -24,10 +24,10 @@ const events = {
|
|
|
24
24
|
* @param callback Event listener callback.
|
|
25
25
|
*/
|
|
26
26
|
function on(event, callback) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const callbacks = events[event];
|
|
28
|
+
if (callbacks) {
|
|
29
|
+
callbacks.push(callback);
|
|
30
|
+
}
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* @function off
|
|
@@ -36,25 +36,26 @@ function on(event, callback) {
|
|
|
36
36
|
* @param callback Event listener callback.
|
|
37
37
|
*/
|
|
38
38
|
function off(event, callback) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
const callbacks = events[event];
|
|
40
|
+
if (callbacks) {
|
|
41
|
+
if (callback) {
|
|
42
|
+
const index = callbacks.indexOf(callback);
|
|
43
|
+
if (index >= 0) {
|
|
44
|
+
callbacks.splice(index, 1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
events[event] = [];
|
|
49
|
+
}
|
|
48
50
|
}
|
|
49
|
-
}
|
|
50
51
|
}
|
|
51
52
|
function emit(event, message, options) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const callbacks = events[event];
|
|
54
|
+
if (callbacks && callbacks.length > 0) {
|
|
55
|
+
for (const callback of callbacks) {
|
|
56
|
+
callback(message, options);
|
|
57
|
+
}
|
|
56
58
|
}
|
|
57
|
-
}
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
export { emit, off, on };
|