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

[박상범] 챕터 7: 자바스크립트 디자인 패턴 (1/3) #42

Merged
merged 1 commit into from
Nov 3, 2024

Conversation

sangbooom
Copy link
Contributor

No description provided.

Copy link
Member

@hyesungoh hyesungoh left a comment

Choose a reason for hiding this comment

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

잘 읽었습니다 👍 👍 궁금한 점 하나 남겼어요!!

Comment on lines +87 to +93
## 7.4 노출 모듈 패턴
일만이 행님이 답답해서 만든 패턴

비공개 함수와 속성에 접근하는 공개 포인터를 만듦.
이렇게 하면 모듈 가장 아래에 위치한 공개 객체를 더 알아보기 쉬워서 가독성 좋음

> 회사에서도 커스텀 훅은 다 노출 모듈 패턴으로 작성함
Copy link
Member

Choose a reason for hiding this comment

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

const foo1;
const foo2;

const bar1;

// ...

const public = {
 foo1, foo2
}
export default public;

대략 이런 모습으로 이해하면 될까요??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

맞아요 전 아래와 같이 좀 더 일반적인 커스텀 훅 형태를 생각했어요!

const useWebView = () => {
  const [isWebView, setIsWebView] = useState(false);

  useEffect(() => {
    if (isWebView) return;

    if (typeof window !== 'undefined' && !!window.ReactNativeWebView) {
      setIsWebView(true);
    }
  }, [isWebView]);

  return {
    isWebView,
  };
};

export default useWebView;

노출 모듈 패턴이 실제로 커스텀 훅과 완전 일치하지 않을 수 있지만! 노출 모듈 패턴의 개념적 특성을 일부 따르고 있다고 봤어요
특히 내부 상태를 캡슐화하고 외부에는 필요한 값만 노출한다는 점에서 유사하다고 생각했슴다

Copy link
Member

Choose a reason for hiding this comment

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

아아 말씀하신대로 이렇게도 적용 예로 볼 수 있겠군요 ?!? 👍 👍

Copy link
Member

@100Gyeon 100Gyeon left a comment

Choose a reason for hiding this comment

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

정리 깔끔하네요👍 잘 읽었습니다!

Copy link
Member

@Seojunhwan Seojunhwan left a comment

Choose a reason for hiding this comment

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

노출 모듈 패턴 설명 감사함니다 , ,

@sangbooom sangbooom merged commit 1f69bfe into main Nov 3, 2024
1 check passed
@sangbooom sangbooom deleted the 챕터7_1/박상범 branch November 3, 2024 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants