Skip to content

Commit 0a39de2

Browse files
Remove generics from examples
1 parent a48cf67 commit 0a39de2

File tree

4 files changed

+15
-110
lines changed

4 files changed

+15
-110
lines changed

examples/capacitor/src/App.tsx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,11 @@ const apiKey = process.env.REACT_APP_STREAM_KEY as string;
1717
const userId = process.env.REACT_APP_USER_ID as string;
1818
const userToken = process.env.REACT_APP_USER_TOKEN as string;
1919

20-
const filters: ChannelFilters = { type: 'messaging', members: {$in: [userId]} };
20+
const filters: ChannelFilters = { type: 'messaging', members: { $in: [userId] } };
2121
const options: ChannelOptions = { state: true, presence: true, limit: 10 };
2222
const sort: ChannelSort = { last_message_at: -1, updated_at: -1 };
2323

24-
type LocalAttachmentType = Record<string, unknown>;
25-
type LocalChannelType = Record<string, unknown>;
26-
type LocalCommandType = string;
27-
type LocalEventType = Record<string, unknown>;
28-
type LocalMessageType = Record<string, unknown>;
29-
type LocalReactionType = Record<string, unknown>;
30-
type LocalUserType = Record<string, unknown>;
31-
32-
type StreamChatGenerics = {
33-
attachmentType: LocalAttachmentType;
34-
channelType: LocalChannelType;
35-
commandType: LocalCommandType;
36-
eventType: LocalEventType;
37-
messageType: LocalMessageType;
38-
reactionType: LocalReactionType;
39-
userType: LocalUserType;
40-
};
41-
42-
const chatClient = StreamChat.getInstance<StreamChatGenerics>(apiKey);
24+
const chatClient = StreamChat.getInstance(apiKey);
4325

4426
if (process.env.REACT_APP_CHAT_SERVER_ENDPOINT) {
4527
chatClient.setBaseURL(process.env.REACT_APP_CHAT_SERVER_ENDPOINT);

examples/typescript/src/App.tsx

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
Window,
1212
} from 'stream-chat-react';
1313

14-
const params = (new Proxy(new URLSearchParams(window.location.search), {
14+
const params = new Proxy(new URLSearchParams(window.location.search), {
1515
get: (searchParams, property) => searchParams.get(property as string),
16-
}) as unknown) as Record<string, string | null>;
16+
}) as unknown as Record<string, string | null>;
1717

1818
const apiKey = process.env.REACT_APP_STREAM_KEY as string;
1919
const userId = params.uid || (process.env.REACT_APP_USER_ID as string);
@@ -23,31 +23,7 @@ const filters: ChannelFilters = { type: 'messaging', members: { $in: [userId] }
2323
const options: ChannelOptions = { state: true, presence: true, limit: 10 };
2424
const sort: ChannelSort = { last_message_at: -1, updated_at: -1 };
2525

26-
type LocalAttachmentType = Record<string, unknown>;
27-
type LocalChannelType = Record<string, unknown>;
28-
type LocalCommandType = string;
29-
type LocalEventType = Record<string, unknown>;
30-
type LocalMemberType = Record<string, unknown>;
31-
type LocalMessageType = Record<string, unknown>;
32-
type LocalPollOptionType = Record<string, unknown>;
33-
type LocalPollType = Record<string, unknown>;
34-
type LocalReactionType = Record<string, unknown>;
35-
type LocalUserType = Record<string, unknown>;
36-
37-
type StreamChatGenerics = {
38-
attachmentType: LocalAttachmentType;
39-
channelType: LocalChannelType;
40-
commandType: LocalCommandType;
41-
eventType: LocalEventType;
42-
memberType: LocalMemberType;
43-
messageType: LocalMessageType;
44-
pollOptionType: LocalPollOptionType;
45-
pollType: LocalPollType;
46-
reactionType: LocalReactionType;
47-
userType: LocalUserType;
48-
};
49-
50-
const chatClient = StreamChat.getInstance<StreamChatGenerics>(apiKey);
26+
const chatClient = StreamChat.getInstance(apiKey);
5127

5228
if (process.env.REACT_APP_CHAT_SERVER_ENDPOINT) {
5329
chatClient.setBaseURL(process.env.REACT_APP_CHAT_SERVER_ENDPOINT);

examples/vite/src/App.tsx

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import {
1515
ChatView,
1616
} from 'stream-chat-react';
1717

18-
const params = (new Proxy(new URLSearchParams(window.location.search), {
18+
const params = new Proxy(new URLSearchParams(window.location.search), {
1919
get: (searchParams, property) => searchParams.get(property as string),
20-
}) as unknown) as Record<string, string | null>;
20+
}) as unknown as Record<string, string | null>;
2121

2222
const parseUserIdFromToken = (token: string) => {
2323
const [, payload] = token.split('.');
@@ -39,32 +39,8 @@ const filters: ChannelFilters = {
3939
const options: ChannelOptions = { limit: 5, presence: true, state: true };
4040
const sort: ChannelSort = { pinned_at: 1, last_message_at: -1, updated_at: -1 };
4141

42-
type LocalAttachmentType = Record<string, unknown>;
43-
type LocalChannelType = Record<string, unknown>;
44-
type LocalCommandType = string;
45-
type LocalEventType = Record<string, unknown>;
46-
type LocalMemberType = Record<string, unknown>;
47-
type LocalMessageType = Record<string, unknown>;
48-
type LocalPollOptionType = Record<string, unknown>;
49-
type LocalPollType = Record<string, unknown>;
50-
type LocalReactionType = Record<string, unknown>;
51-
type LocalUserType = Record<string, unknown>;
52-
53-
type StreamChatGenerics = {
54-
attachmentType: LocalAttachmentType;
55-
channelType: LocalChannelType;
56-
commandType: LocalCommandType;
57-
eventType: LocalEventType;
58-
memberType: LocalMemberType;
59-
messageType: LocalMessageType;
60-
pollOptionType: LocalPollOptionType;
61-
pollType: LocalPollType;
62-
reactionType: LocalReactionType;
63-
userType: LocalUserType;
64-
};
65-
6642
const App = () => {
67-
const chatClient = useCreateChatClient<StreamChatGenerics>({
43+
const chatClient = useCreateChatClient({
6844
apiKey,
6945
tokenOrProvider: userToken,
7046
userData: { id: userId },

src/stories/utils.tsx

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,31 @@
11
import React, { PropsWithChildren, useEffect, useState } from 'react';
22
import { Chat } from '../';
3-
import {
4-
DefaultGenerics,
5-
ExtendableGenerics,
6-
OwnUserResponse,
7-
StreamChat,
8-
TokenOrProvider,
9-
UserResponse,
10-
} from 'stream-chat';
3+
import { OwnUserResponse, StreamChat, TokenOrProvider, UserResponse } from 'stream-chat';
114

125
const appKey = import.meta.env.E2E_APP_KEY;
136
if (!appKey || typeof appKey !== 'string') {
147
throw new Error('expected APP_KEY');
158
}
169
export const streamAPIKey = appKey;
1710

18-
type LocalAttachmentType = Record<string, unknown>;
19-
type LocalChannelType = Record<string, unknown>;
20-
type LocalCommandType = string;
21-
type LocalEventType = Record<string, unknown>;
22-
type LocalMessageType = Record<string, unknown>;
23-
type LocalReactionType = Record<string, unknown>;
24-
type LocalUserType = Record<string, unknown>;
25-
26-
export type StreamChatGenerics = {
27-
attachmentType: LocalAttachmentType;
28-
channelType: LocalChannelType;
29-
commandType: LocalCommandType;
30-
eventType: LocalEventType;
31-
messageType: LocalMessageType;
32-
reactionType: LocalReactionType;
33-
userType: LocalUserType;
34-
};
35-
3611
export type ConnectedUserProps = PropsWithChildren<{
3712
token: string;
3813
userId: string;
3914
}>;
4015

41-
const useClient = <SCG extends ExtendableGenerics = DefaultGenerics>({
16+
const useClient = ({
4217
apiKey,
4318
tokenOrProvider,
4419
userData,
4520
}: {
4621
apiKey: string;
4722
tokenOrProvider: TokenOrProvider;
48-
userData: OwnUserResponse<SCG> | UserResponse<SCG>;
23+
userData: OwnUserResponse | UserResponse;
4924
}) => {
50-
const [chatClient, setChatClient] = useState<StreamChat<SCG> | null>(null);
25+
const [chatClient, setChatClient] = useState<StreamChat | null>(null);
5126

5227
useEffect(() => {
53-
const client = new StreamChat<SCG>(apiKey);
28+
const client = new StreamChat(apiKey);
5429

5530
let didUserConnectInterrupt = false;
5631
const connectionPromise = client.connectUser(userData, tokenOrProvider).then(() => {
@@ -72,12 +47,8 @@ const useClient = <SCG extends ExtendableGenerics = DefaultGenerics>({
7247
return chatClient;
7348
};
7449

75-
export const ConnectedUser = <SCG extends DefaultGenerics = StreamChatGenerics>({
76-
children,
77-
token,
78-
userId,
79-
}: ConnectedUserProps) => {
80-
const client = useClient<SCG>({
50+
export const ConnectedUser = ({ children, token, userId }: ConnectedUserProps) => {
51+
const client = useClient({
8152
apiKey: streamAPIKey,
8253
tokenOrProvider: token,
8354
userData: { id: userId },

0 commit comments

Comments
 (0)