Skip to content

Commit

Permalink
fix: Fix eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenKirschbaum committed Jun 23, 2024
1 parent ce78329 commit 951dc93
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions example/src/App.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ vi.mock('react-stomp-hooks', async () => {
};
})

// eslint-disable-next-line vitest/expect-expect
it('app renders without crashing', () => {
render(<App />);
})
1 change: 1 addition & 0 deletions example/src/Components.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ afterEach(() => {


//Test Subscribing Component using provided Mock implementation
// eslint-disable-next-line vitest/expect-expect
it('Subscribing component works', () => {
//Render Subscribing Component, with StompSessionProviderMock
render(
Expand Down
3 changes: 2 additions & 1 deletion src/components/StompSessionProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { StompSessionSubscription } from '../interfaces/StompSessionSubscription
* Please consult the @stomp/stompjs documentation for more information.
*/
function StompSessionProvider(props: StompSessionProviderProps) {
let { url, children, stompClientOptions, ...stompOptions } = props;
const { url, children, stompClientOptions, ...otherProps } = props;
let stompOptions = otherProps;

// Support old API
if (stompClientOptions) stompOptions = stompClientOptions;
Expand Down
6 changes: 5 additions & 1 deletion src/hoc/withStompClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import React from 'react';
import useStompClient from '../hooks/useStompClient';

function withStompClient<P>(WrappedComponent: React.ComponentType<P>) {
return (props: P) => {
const comp = (props: P) => {
const stompClient = useStompClient();
return <WrappedComponent stompClient={stompClient} {...props} />;
};

comp.displayName = `withStompClient(${WrappedComponent.displayName || WrappedComponent.name})`;

return comp;
}

export default withStompClient;
8 changes: 6 additions & 2 deletions src/hoc/withSubscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function withSubscription<P>(
destinations: string | string[],
headers: StompHeaders = {}
) {
return (props: P) => {
const comp = (props: P) => {
const ref = useRef<MessageReceiverInterface>();
useSubscription(
destinations,
Expand All @@ -21,9 +21,13 @@ function withSubscription<P>(
headers
);

// @ts-ignore
// @ts-expect-error - Ref type incompatible
return <WrappedComponent ref={ref} {...props} />;
};

comp.displayName = `withSubscription(${WrappedComponent.displayName || WrappedComponent.name})`;

return comp;
}

export default withSubscription;
4 changes: 2 additions & 2 deletions src/interfaces/StompMessageReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export interface MessageReceiverInterface {
onMessage: messageCallbackType;
}

export type StompMessageReceiver<P = {}> = React.ComponentClass<P> & {
new (props: P, context?: any): React.Component<P> & MessageReceiverInterface;
export type StompMessageReceiver<P = object> = React.ComponentClass<P> & {
new (props: P, context?: unknown): React.Component<P> & MessageReceiverInterface;
};
5 changes: 3 additions & 2 deletions src/interfaces/StompSessionProviderProps.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { StompConfig } from '@stomp/stompjs';
import { ReactNode } from 'react';

export interface StompSessionProviderProps extends StompConfig {
url: string;
children: any;
children: ReactNode;
/**
* @deprecated
*/
stompClientOptions?: any;
stompClientOptions?: object;
}
4 changes: 2 additions & 2 deletions src/mock/StompSessionProviderMock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { getMockClient } from './client';
*/
export default function StompSessionProviderMock(props: {
children: React.ReactNode;
client?: any;
client?: unknown;
}) {
return (
<StompContext.Provider
value={{
subscribe: subscribeMock,
// @ts-ignore
// @ts-expect-error - Mock client is not a full client
client: props.client ?? getMockClient()
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/mock/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function mockClientPublish(params: IPublishParams) {
messages.set(params.destination, []);
}

// @ts-ignore
// @ts-expect-error - possible undefined
messages.get(params.destination).push(params);
}

Expand Down
14 changes: 7 additions & 7 deletions src/mock/subscriptions.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { IMessage } from '@stomp/stompjs';
import { messageCallbackType, StompHeaders } from '@stomp/stompjs';

export const subscriptions = new Map<string, Map<string, Function>>();
export const subscriptions = new Map<string, Map<string, messageCallbackType>>();

export function subscribeMock(
destination: string,
callback: messageCallbackType,
// @ts-ignore
// @ts-expect-error - irrelevant in mock
// eslint-disable-next-line @typescript-eslint/no-unused-vars
headers: StompHeaders = {}
) {
const subscriptionId = Math.random().toString(36).substr(2, 9);

if (!subscriptions.has(destination)) {
subscriptions.set(destination, new Map<string, Function>());
subscriptions.set(destination, new Map<string, messageCallbackType>());
}

// @ts-ignore
// @ts-expect-error undefined check
subscriptions.get(destination).set(subscriptionId, callback);

return () => {
// @ts-ignore
// @ts-expect-error undefined check
subscriptions.get(destination).delete(subscriptionId);
};
}
Expand All @@ -35,8 +35,8 @@ export function mockReceiveMessage(
message: IMessage
): void {
if (subscriptions.has(destination)) {
// @ts-ignore
subscriptions.get(destination).forEach((callback: Function) => {
// @ts-expect-error undefined check
subscriptions.get(destination).forEach((callback: messageCallbackType) => {
callback(message);
});
}
Expand Down

0 comments on commit 951dc93

Please sign in to comment.