10000 feat(useEventSource): return `lastEventId` by pkc918 · Pull Request #3984 · vueuse/vueuse · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(useEventSource): return lastEventId #3984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/core/useEventSource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export interface UseEventSourceReturn<Events extends string[]> {
* Reference to the current EventSource instance.
*/
eventSource: Ref<EventSource | null>
/**
* The last event ID string, for server-sent events.
* @see https://developer. 8000 mozilla.org/en-US/docs/Web/API/MessageEvent/lastEventId
*/
lastEventId: Ref<string | null>
}

function resolveNestedOptions<T>(options: T | true): T {
Expand Down Expand Up @@ -109,6 +114,7 @@ export function useEventSource<Events extends string[]>(
const eventSource = ref(null) as Ref<EventSource | null>
const error = shallowRef(null) as Ref<Event | null>
const urlRef = toRef(url)
const lastEventId = shallowRef<string | null>(null)

let explicitlyClosed = false
let retried = 0
Expand Down Expand Up @@ -169,6 +175,7 @@ export function useEventSource<Events extends string[]>(
es. MessageEvent) => {
event.value = null
data.value = e.data
lastEventId.value = e.lastEventId
}

for (const event_name of events) {
Expand Down Expand Up @@ -201,5 +208,6 @@ export function useEventSource<Events extends string[]>(
error,
open,
close,
lastEventId,
}
}
0