@quicktvui/web-cli 3.0.0 → 3.1.1
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/lib/HotReloader.js
CHANGED
|
@@ -12,8 +12,7 @@ const signale = require('signale')
|
|
|
12
12
|
class HotReloader {
|
|
13
13
|
constructor() {
|
|
14
14
|
this.clients = new Set()
|
|
15
|
-
this.
|
|
16
|
-
this.lastEventData = null
|
|
15
|
+
this.lastEvent = null
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
/**
|
|
@@ -31,8 +30,8 @@ class HotReloader {
|
|
|
31
30
|
res.write(`data: ${JSON.stringify({ type: 'connected', timestamp: Date.now() })}\n\n`)
|
|
32
31
|
|
|
33
32
|
// 如果有最近的事件,立即发送
|
|
34
|
-
if (this.
|
|
35
|
-
res.write(`data: ${JSON.stringify(
|
|
33
|
+
if (this.lastEvent) {
|
|
34
|
+
res.write(`data: ${JSON.stringify(this.lastEvent)}\n\n`)
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
this.clients.add(res)
|
|
@@ -58,8 +57,7 @@ class HotReloader {
|
|
|
58
57
|
...data,
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
this.
|
|
62
|
-
this.lastEventData = data
|
|
60
|
+
this.lastEvent = event
|
|
63
61
|
|
|
64
62
|
this._broadcast(event)
|
|
65
63
|
signale.info(`[HotReloader] 通知 ${this.clients.size} 个客户端: bundle-update`)
|
|
@@ -75,8 +73,7 @@ class HotReloader {
|
|
|
75
73
|
reason,
|
|
76
74
|
}
|
|
77
75
|
|
|
78
|
-
this.
|
|
79
|
-
this.lastEventData = { reason }
|
|
76
|
+
this.lastEvent = event
|
|
80
77
|
|
|
81
78
|
this._broadcast(event)
|
|
82
79
|
signale.info(`[HotReloader] 通知 ${this.clients.size} 个客户端: full-reload`)
|
|
@@ -93,8 +90,7 @@ class HotReloader {
|
|
|
93
90
|
timestamp: Date.now(),
|
|
94
91
|
}
|
|
95
92
|
|
|
96
|
-
this.
|
|
97
|
-
this.lastEventData = { status, message }
|
|
93
|
+
this.lastEvent = event
|
|
98
94
|
|
|
99
95
|
this._broadcast(event)
|
|
100
96
|
}
|
|
@@ -104,8 +100,7 @@ class HotReloader {
|
|
|
104
100
|
* 防止 SSE 重连后再次发送旧的 bundle-update 导致无限刷新
|
|
105
101
|
*/
|
|
106
102
|
clearLastEvent() {
|
|
107
|
-
this.
|
|
108
|
-
this.lastEventData = null
|
|
103
|
+
this.lastEvent = null
|
|
109
104
|
}
|
|
110
105
|
|
|
111
106
|
/**
|