webpack-dev-service 0.5.4 → 0.5.6
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 +109 -111
- package/client/cjs/events.cjs +32 -33
- package/client/cjs/hot.cjs +60 -61
- package/client/cjs/index.cjs +8 -10
- package/client/cjs/main.cjs +60 -63
- package/client/cjs/ui/overlay.cjs +63 -64
- package/client/cjs/ui/progress.cjs +35 -35
- package/client/cjs/ui/utils/ansi/index.cjs +413 -439
- 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 +109 -111
- package/client/esm/events.js +32 -33
- package/client/esm/hot.js +60 -61
- package/client/esm/index.js +8 -8
- package/client/esm/main.js +60 -63
- package/client/esm/ui/overlay.js +63 -64
- package/client/esm/ui/progress.js +35 -35
- package/client/esm/ui/utils/ansi/index.js +413 -439
- 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 +10 -9
- package/server/cjs/dev.cjs +36 -30
- package/server/cjs/hot.cjs +177 -174
- package/server/cjs/index.cjs +17 -16
- package/server/esm/dev.js +32 -28
- package/server/esm/hot.js +172 -171
- package/server/esm/index.js +13 -14
- 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 +42 -46
- 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.6
|
|
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.6
|
|
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.6
|
|
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
|
-
|
|
100
|
-
if (!href) {
|
|
101
|
-
return escapedValue;
|
|
102
|
-
}
|
|
103
|
-
return `<a href=${href} target="_blank">${escapedValue}</a>`;
|
|
104
|
-
}
|
|
105
|
-
const inlineStyle = JSON.stringify(`${styles.join(';')};`);
|
|
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) {
|
|
106
100
|
if (!href) {
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
return `<a
|
|
101
|
+
return escapedValue;
|
|
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>`;
|
|
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.6
|
|
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,113 +16,111 @@ 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
|
-
|
|
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
|
+
} else if (error) {
|
|
28
|
+
console.error(error);
|
|
29
|
+
console.warn('Use fallback update but you turn off live reload, please reload by yourself.');
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const applyUpdateAsync = () => {
|
|
33
|
+
updateTimer = self.setTimeout(() => {
|
|
34
|
+
applyUpdate(options.hmr, fallback);
|
|
35
|
+
}, UPDATE_DELAY);
|
|
36
|
+
};
|
|
37
|
+
const onInvalid = () => {
|
|
38
|
+
clearTimeout(updateTimer);
|
|
39
|
+
if (options.progress) {
|
|
40
|
+
progress.update(0);
|
|
41
|
+
progress.show();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const onProgress = ({ value }) => {
|
|
45
|
+
if (options.progress) {
|
|
46
|
+
progress.update(value);
|
|
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']
|
|
49
56
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
57
|
+
if (options.overlay) {
|
|
58
|
+
overlay.setProblems(type, problems);
|
|
59
|
+
}
|
|
60
|
+
const [name, method] = maps[type];
|
|
61
|
+
const debug = console[method];
|
|
62
|
+
for (const { moduleName, message } of problems) {
|
|
63
|
+
debug(`\x1b[0m${name} in ${moduleName}\r\n\x1b[0m${message}`);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const onProblems = ({ errors, warnings }) => {
|
|
67
|
+
progress.hide();
|
|
68
|
+
setProblems('errors', errors);
|
|
69
|
+
setProblems('warnings', warnings);
|
|
70
|
+
if (options.overlay) {
|
|
71
|
+
overlay.show();
|
|
72
|
+
}
|
|
73
|
+
if (errors.length <= 0) {
|
|
74
|
+
applyUpdateAsync();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const onSuccess = () => {
|
|
78
|
+
overlay.hide();
|
|
79
|
+
progress.hide();
|
|
80
|
+
applyUpdateAsync();
|
|
81
|
+
};
|
|
82
|
+
const parseMessage = message => {
|
|
83
|
+
try {
|
|
84
|
+
return JSON.parse(message.data);
|
|
85
|
+
} catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const createWebSocket = url => {
|
|
90
|
+
const ws = new WebSocket(url);
|
|
91
|
+
ws.onmessage = message => {
|
|
92
|
+
const parsed = parseMessage(message);
|
|
93
|
+
if (parsed) {
|
|
94
|
+
const { action, payload } = parsed;
|
|
95
|
+
switch (action) {
|
|
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;
|
|
89
111
|
}
|
|
112
|
+
emit(action, payload, options);
|
|
113
|
+
}
|
|
90
114
|
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
};
|
|
115
|
+
ws.onclose = () => {
|
|
116
|
+
overlay.hide();
|
|
117
|
+
progress.hide();
|
|
118
|
+
setTimeout(() => {
|
|
119
|
+
createWebSocket(url);
|
|
120
|
+
}, RETRY_INTERVAL);
|
|
124
121
|
};
|
|
125
|
-
|
|
122
|
+
};
|
|
123
|
+
createWebSocket(`${options.origin}${options.path}`);
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
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.6
|
|
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,26 +36,25 @@ 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
|
-
|
|
48
|
-
events[event] = [];
|
|
49
|
-
}
|
|
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
|
+
} else {
|
|
47
|
+
events[event] = [];
|
|
50
48
|
}
|
|
49
|
+
}
|
|
51
50
|
}
|
|
52
51
|
function emit(event, message, options) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
52
|
+
const callbacks = events[event];
|
|
53
|
+
if (callbacks && callbacks.length > 0) {
|
|
54
|
+
for (const callback of callbacks) {
|
|
55
|
+
callback(message, options);
|
|
58
56
|
}
|
|
57
|
+
}
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
export { emit, off, on };
|