Skip to content

Commit

Permalink
chore: remove deprecated extraOptions
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Reining <[email protected]>

# Conflicts:
#	src/eventsource.ts
  • Loading branch information
lukas-reining committed Dec 15, 2024
1 parent bf882f3 commit 8221e47
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 35 deletions.
26 changes: 9 additions & 17 deletions src/eventsource.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { http, HttpResponse as MswHttpResponse } from 'msw';
import { server } from '../mocks/node';
import { CustomEventSource as EventSource, CustomEvent } from './eventsource';
import { CustomEvent, CustomEventSource as EventSource } from './eventsource';
import DoneCallback = jest.DoneCallback;

describe('EventSource', () => {
Expand Down Expand Up @@ -52,15 +52,10 @@ describe('EventSource', () => {
return globalThis.fetch(input, init);
}) as typeof fetch;

const ev = new EventSource(
'http://localhost/sse',
{
disableRetry: true,
},
{
fetchInput: fetchFn,
},
);
const ev = new EventSource('http://localhost/sse', {
disableRetry: true,
fetch: fetchFn,
});

ev.onopen = (event) => {
expect(event).toBeInstanceOf(Event);
Expand All @@ -76,13 +71,10 @@ describe('EventSource', () => {
return globalThis.fetch(input, init);
}) as typeof fetch;

const ev = new EventSource(
'http://localhost/sse',
{
disableRetry: true,
fetch: fetchFn,
},
);
const ev = new EventSource('http://localhost/sse', {
disableRetry: true,
fetch: fetchFn,
});

ev.onopen = (event) => {
expect(event).toBeInstanceOf(Event);
Expand Down
18 changes: 0 additions & 18 deletions src/eventsource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ export type EventSourceOptions = {
omitCredentials?: boolean;
} & Omit<RequestInit, 'cache' | 'credentials' | 'signal'>;

/**
* @deprecated
*/
export type EventSourceExtraOptions = {
/**
* @deprecated Use {@link EventSourceOptions#fetch} instead
*/
fetchInput?: typeof fetch;
};

export type CustomEvent = Event & {
response?: Response;
};
Expand Down Expand Up @@ -73,7 +63,6 @@ export class CustomEventSource extends EventTarget implements EventSource {
| null = null;

public readonly options: EventSourceInit & EventSourceOptions;
private readonly extraOptions?: EventSourceExtraOptions;
private abortController?: AbortController;
private timeoutId: ReturnType<typeof setTimeout> | undefined = undefined;
private retry: number;
Expand All @@ -84,14 +73,9 @@ export class CustomEventSource extends EventTarget implements EventSource {
constructor(
url: string | URL,
initDict?: EventSourceInit & EventSourceOptions,
/**
* @deprecated Use the related options in initDict
*/
extraOptions?: EventSourceExtraOptions,
) {
super();
this.options = initDict ?? {};
this.extraOptions = extraOptions;
this.url = url instanceof URL ? url.toString() : url;
this.retry = initDict?.retry ?? 5000;

Expand Down Expand Up @@ -153,8 +137,6 @@ export class CustomEventSource extends EventTarget implements EventSource {

const response = this.options.fetch
? await this.options.fetch(this.url, fetchOptions)
: this.extraOptions?.fetchInput
? await this.extraOptions.fetchInput(this.url, fetchOptions)
: await globalThis.fetch(this.url, fetchOptions);

// https://html.spec.whatwg.org/multipage/server-sent-events.html#dom-eventsource (Step 15)
Expand Down

0 comments on commit 8221e47

Please sign in to comment.