Skip to content
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

[FE] refactor: DataChannel 전역 상태로 변경 #194

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

HBSPS
Copy link
Collaborator

@HBSPS HBSPS commented Dec 6, 2023

PR 설명

  • DataChannel 전역 상태로 변경

✅ 완료한 기능 명세

  • codeDataChannel 전역 상태로 변경
  • languageDataChannel 전역 상태로 변경

📸 스크린샷

import { create } from 'zustand';
import { DataChannel } from '@/types/RTCConnection';

interface DataChannels {
  codeDataChannel: DataChannel[];
  addCodeDataChannel: (socketId: string, dataChannel: RTCDataChannel) => void;
  removeCodeDataChannel: (value: { id: string }) => void;

  languageDataChannel: DataChannel[];
  addLanguageChannel: (socketId: string, dataChannel: RTCDataChannel) => void;
  removeLanguageChannel: (value: { id: string }) => void;
}

const useDataChannels = create<DataChannels>((set) => ({
  codeDataChannel: [],
  addCodeDataChannel: (id, dataChannel) => set((state) => ({ ...state, codeDataChannel: [...state.codeDataChannel, { id, dataChannel }] })),
  removeCodeDataChannel: (data) =>
    set((state) => ({ ...state, codeDataChannel: [...state.codeDataChannel.filter(({ id }) => id !== data.id)] })),

  languageDataChannel: [],
  addLanguageChannel: (id, dataChannel) =>
    set((state) => ({ ...state, languageDataChannel: [...state.languageDataChannel, { id, dataChannel }] })),
  removeLanguageChannel: (data) =>
    set((state) => ({ ...state, languageDataChannel: [...state.languageDataChannel.filter(({ id }) => id !== data.id)] })),
}));

export default useDataChannels;

고민과 해결과정

  • 전역 상태로 변경한 이유
    • 매우 깊은 depth 까지 props drilling이 발생했으며 그 과정에서 중간 단계에 있는 컴포넌트에 불필요한 재렌더링이 되는 것을 해결하기 위해

@HBSPS HBSPS added enhancement 개선 또는 피드백 반영 FrontEnd 프론트엔드 관련 labels Dec 6, 2023
@HBSPS HBSPS requested a review from d0422 December 6, 2023 06:20
@HBSPS HBSPS self-assigned this Dec 6, 2023
Copy link
Collaborator

@d0422 d0422 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!


const errorCallback = createAuthFailCallback(() => showLoginModal({ code: plainCode }));
const crdt = useContext(CRDTContext);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useCRDT로 보일러플레이트코드를 줄일 수 있지 않을까 합니다!

@HBSPS HBSPS merged commit 577622b into boostcampwm2023:dev Dec 6, 2023
6 checks passed
@HBSPS HBSPS mentioned this pull request Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 개선 또는 피드백 반영 FrontEnd 프론트엔드 관련
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants