File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed
packages/core/useEventSource Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,11 @@ export interface UseEventSourceReturn<Events extends string[]> {
81
81
* Reference to the current EventSource instance.
82
82
*/
83
83
eventSource : Ref < EventSource | null >
84
+ /**
85
+ * The last event ID string, for server-sent events.
86
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/lastEventId
87
+ */
88
+ lastEventId : Ref < string | null >
84
89
}
85
90
86
91
function resolveNestedOptions < T > ( options : T | true ) : T {
@@ -109,6 +114,7 @@ export function useEventSource<Events extends string[]>(
109
114
const eventSource = ref ( null ) as Ref < EventSource | null >
110
115
const error = shallowRef ( null ) as Ref < Event | null >
111
116
const urlRef = toRef ( url )
117
+ const lastEventId = shallowRef < string | null > ( null )
112
118
113
119
let explicitlyClosed = false
114
120
let retried = 0
@@ -169,6 +175,7 @@ export function useEventSource<Events extends string[]>(
169
175
es . onmessage = ( e : MessageEvent ) => {
170
176
event . value = null
171
177
data . value = e . data
178
+ lastEventId . value = e . lastEventId
172
179
}
173
180
174
181
for ( const event_name of events ) {
@@ -201,5 +208,6 @@ export function useEventSource<Events extends string[]>(
201
208
error,
202
209
open,
203
210
close,
211
+ lastEventId,
204
212
}
205
213
}
You can’t perform that action at this time.
0 commit comments