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

feat(react): update wrap as builder pattern #280

Merged
merged 4 commits into from
Nov 4, 2023

Conversation

manudeli
Copy link
Member

@manudeli manudeli commented Oct 30, 2023

related with #269

Overview

I update wrap as builder pattern to remove wrap nesting.

AS-IS (wrap nesting with importing all public apis(ErrorBoundary, Suspense, etc.))

import { ErrorBoundary, ErrorBoundaryGroup, Suspense, useErrorBoundary, wrap } from '@suspensive/react'
import { UseSuspenseQuery } from '~/components'
import { api } from '~/utils'

const logError = (error: Error) => console.error(error)

export default wrap(ErrorBoundaryGroup, { blockOutside: false })(
  wrap(ErrorBoundary, { fallback: (props) => <>{props.error.message}</>, onError: logError })(
    wrap(Suspense.CSROnly, { fallback: <>loading...</> })(() => {
      const errorBoundary = useErrorBoundary()

      return (
        <>
          <button onClick={() => errorBoundary.setError(new Error('trigger error by useErrorBoundary().setError'))}>
            trigger error by useErrorBoundary().setError
          </button>
          <UseSuspenseQuery queryKey={['with', 1] as const} queryFn={() => api.delay(200, { percentage: 50 })} />
        </>
      )
    })
  )
)

TO-BE (wrap builder with no import)

import { useErrorBoundary, wrap } from '@suspensive/react' // It's easy

const logError = (error: Error) => console.error(error)

export default wrap
  .ErrorBoundaryGroup({ blockOutside: false })
  .ErrorBoundary({ fallback: (props) => <div>{props.error.message}</div>, onError: logError })
  .Suspense.CSROnly({ fallback: 'loading...' }) // CSROnly chaining available
  .on<{ text: string }>(({ text }) => { // We can type of Page at once. generic also available
    const errorBoundary = useErrorBoundary()

    return (
      <div>
        <button onClick={() => errorBoundary.setError(new Error('trigger error by useErrorBoundary().setError'))}>
          trigger error by useErrorBoundary().setError
        </button>
        {text}
      </div>
    )
  })

PR Checklist

  • I did below actions if need
  1. I read the Contributing Guide
  2. I added documents and tests.

@manudeli manudeli self-assigned this Oct 30, 2023
@changeset-bot
Copy link

changeset-bot bot commented Oct 30, 2023

⚠️ No Changeset found

Latest commit: 57d4423

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 2, 2023 0:23am
visualization ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 2, 2023 0:23am

@vercel vercel bot temporarily deployed to Preview – visualization October 30, 2023 10:23 Inactive
@manudeli manudeli changed the title feat(react): other implementation of wrap feat(react): update wrap as builder pattern Oct 30, 2023
@vercel vercel bot temporarily deployed to Preview – docs October 30, 2023 10:24 Inactive
@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 30, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@codecov
Copy link

codecov bot commented Oct 30, 2023

Codecov Report

Merging #280 (57d4423) into react/feat/wrap (d1a04f7) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@                Coverage Diff                @@
##           react/feat/wrap      #280   +/-   ##
=================================================
  Coverage           100.00%   100.00%           
=================================================
  Files                   24        24           
  Lines                  752       839   +87     
  Branches               126       143   +17     
=================================================
+ Hits                   752       839   +87     
Components Coverage Δ
@suspensive/react 100.00% <100.00%> (ø)
@suspensive/react-query ∅ <ø> (∅)
@suspensive/react-await 100.00% <ø> (ø)

@vercel vercel bot temporarily deployed to Preview – docs October 30, 2023 19:53 Inactive
@vercel vercel bot temporarily deployed to Preview – visualization October 31, 2023 13:02 Inactive
@vercel vercel bot temporarily deployed to Preview – docs October 31, 2023 13:02 Inactive
@vercel vercel bot temporarily deployed to Preview – docs November 2, 2023 12:22 Inactive
@vercel vercel bot temporarily deployed to Preview – visualization November 2, 2023 12:23 Inactive
Copy link
Member

@minsoo-web minsoo-web left a comment

Choose a reason for hiding this comment

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

GooD!

@manudeli
Copy link
Member Author

manudeli commented Nov 2, 2023

@okinawaa Review this Pull Request please. I want to get approval from all maintainers because this new feature will be important change of @suspensive/react

@manudeli
Copy link
Member Author

manudeli commented Nov 4, 2023

@okinawaa I merge this to react/feat/wrap first, because I think this branch's implementation is better than it. then review react/feat/wrap's Pull Request plesae. If it have problem, I will change it

@manudeli manudeli merged commit cb23858 into react/feat/wrap Nov 4, 2023
16 checks passed
@manudeli manudeli deleted the react/feat/wrap-other-implementation branch November 4, 2023 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants