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

useTripleClientMetadata / useTripleClientActions 통합 #2120

Open
polysiya opened this issue Aug 26, 2022 · 2 comments
Open

useTripleClientMetadata / useTripleClientActions 통합 #2120

polysiya opened this issue Aug 26, 2022 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@polysiya
Copy link
Contributor

useTripleClientMetadatauseTripleClientActions를 합쳐서 useTripleNativeApp과 같은 context로 합치는 게 어떨까요?

현재의 문제점

useTripleClientMetadata로 제공되는 모든 함수는 optional인데 사실 useTripleClientMetadata의 값인 app의 존재여부에 달려있습니다.
2개의 context는 서로 의존적이지만 각각 제공되고 있고, 당연히 타입 선언도 독립적입니다.

이상적으로는 두 context를 합쳐서 아래와 같은 value를 제공하는 context가 되는 것이 좋을 것 같습니다.

type TripleNativeApp = {
  name: 'Triple-iOS' | 'Triple-Android'
  version: string
  actions: {
    // ...native-interface functions
  }
}

이렇게 변경하면 아래와 같이 됩니다.
BEFORE (코드)

  const { closeWindow } = useTripleClientActions()

  return (
    ...
      {closeWindow ? (
        <Navbar>
          <Navbar.Item floated="left" icon="back" onClick={closeWindow} />
        </Navbar>
      ) : null}
    ...
  )

AFTER

  const app = useTripleNativeApp()

  return (
    ...
      {app ? (
        <Navbar>
          <Navbar.Item floated="left" icon="back" onClick={app.actions.closeWindow} />
        </Navbar>
      ) : null}
    ...
  )

BEFORE (코드)

  const app = useTripleClientMetadata()
  const { subscribe, unsubscribe } = useTripleClientActions()

  useEffect(() => {
    if (!app) {
      const handleMessage = ({ data }: MessageEvent) => {
        handleVerifiedMessage(data)
      }

      window.addEventListener('message', handleMessage)

      return () => {
        window.removeEventListener('message', handleMessage)
      }
    } else if (subscribe && unsubscribe) {
      subscribe('receiveMessage', handleVerifiedMessage)

      return () => {
        unsubscribe('receiveMessage', handleVerifiedMessage)
      }
    }
  }, [])

AFTER

  const app = useTripleNativeApp()
  const { subscribe, unsubscribe } = useTripleClientActions()

  useEffect(() => {
    if (!app) {
      const handleMessage = ({ data }: MessageEvent) => {
        handleVerifiedMessage(data)
      }

      window.addEventListener('message', handleMessage)

      return () => {
        window.removeEventListener('message', handleMessage)
      }
    } else {
      const {
        actions: { subscribe, unsubscribe }
      } = app

      subscribe('receiveMessage', handleVerifiedMessage)

      return () => {
        unsubscribe('receiveMessage', handleVerifiedMessage)
      }
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])
@polysiya polysiya added the enhancement New feature or request label Aug 26, 2022
@drakang4
Copy link
Contributor

그러면 기존 훅 2개는 제거되는건가요?

@polysiya
Copy link
Contributor Author

deprecated 시키면 될 것 같아요. 새로 제공될 훅으로 완전히 대체하는 것을 생각했어요!

@drakang4 drakang4 added this to the v13 milestone Jan 12, 2023
@drakang4 drakang4 modified the milestones: v13, v14 Jul 5, 2023
@drakang4 drakang4 modified the milestones: v14, v15 May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants