Skip to content

Commit 61d76b4

Browse files
authored
fix: pubsub subscriber in useEffect (#814)
### issue * pubSub subscriber has been undefined, so couldn't remove the previous subscriptions * delete command has been used to Array, but it's for Object ### Fix * move the pubSub Subscriber into the useEffect sope for making effective * use splice instead of delete in the pubSubFactory
1 parent 1d3c387 commit 61d76b4

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/lib/pubSub/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const pubSubFactory = (): PubSubTypes => {
2626
// Provide handle back for removal of topic
2727
return {
2828
remove: () => {
29-
delete topics[topic][index];
29+
topics[topic].splice(index, 1);
3030
},
3131
};
3232
},

src/modules/Channel/context/hooks/useHandleChannelPubsubEvents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export const useHandleChannelPubsubEvents = ({
2424
dispatcher,
2525
scrollRef,
2626
}: UseHandlePubsubEventsParams): void => {
27-
const subscriber = new Map();
2827
useEffect(() => {
28+
const subscriber = new Map();
2929
if (pubSub?.subscribe) {
3030
subscriber.set(PUBSUB_TOPICS.SEND_USER_MESSAGE, pubSub.subscribe(PUBSUB_TOPICS.SEND_USER_MESSAGE, (props) => {
3131
const { channel, message } = props;

src/modules/Thread/context/hooks/useHandleThreadPubsubEvents.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ export default function useHandleThreadPubsubEvents({
2828
threadDispatcher,
2929
}: StaticProps): void {
3030
useEffect(() => {
31-
const pubSubHandler = (): Map<any, any> => {
32-
const subscriber = new Map();
33-
if (!pubSub || !pubSub.subscribe) {
34-
return subscriber;
35-
}
31+
const subscriber = new Map();
32+
if (pubSub?.subscribe) {
33+
// TODO: subscribe ON_FILE_INFO_UPLOADED
3634
subscriber.set(topics.SEND_MESSAGE_START, pubSub.subscribe(topics.SEND_MESSAGE_START, (props) => {
3735
const {
3836
channel,
@@ -143,8 +141,7 @@ export default function useHandleThreadPubsubEvents({
143141
});
144142
}
145143
}));
146-
};
147-
const subscriber = pubSubHandler();
144+
}
148145
return () => {
149146
subscriber?.forEach((s) => {
150147
try {

0 commit comments

Comments
 (0)