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: Added support for types in overlay.openAsync #88

Closed
wants to merge 9 commits into from

Conversation

XionWCFM
Copy link
Contributor

@XionWCFM XionWCFM commented Oct 9, 2024

Description

The existing overlay.openAsync must always respect generic passing and close(param:T).

// cause typescript error
overlay.openAsync()

// work
overlay.openAsync<boolean>()

This creates unnecessary syntax even in situations where you just need to await.

and I also wanted to provide a way to resolve for use cases that only use unmount, so I created this API.

overlay.openAsync<boolean>(({unmount}) => {
  unmount(false) // work
})

One thing to note about this usage is that the Promise is settled with the value at the time of the first call.

That is, in this use case, the resolve value is:

// result is true
const result = overlay.openAsync<boolean>(({close,unmount}) => {
  close(true)
  unmount(false)
})

Changes

To improve this and provide a little better usability I modified the type some more. and also implemented an unmount function for openAsync.

How Has This Been Tested?

  • Testing for type changes was performed on major changes.

  • I wrote test code to test the added behavior.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have performed a self-review of my own code.
  • My code is commented, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • Any dependent changes have been merged and published in downstream modules.

Further Comments

Internal types have become more complex to provide more advanced type support.

Because typescript considers the false type to be expandable on void, we had to use the ternary operator twice.

type Example = { close: T extends void ? () => void : T extends boolean ? (param: boolean) => void : (param: T) => void; }

Is there a better way?


Thank you!

@XionWCFM XionWCFM requested a review from jungpaeng as a code owner October 9, 2024 10:52
Copy link

changeset-bot bot commented Oct 9, 2024

⚠️ No Changeset found

Latest commit: b7b72a3

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

Copy link

vercel bot commented Oct 9, 2024

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

Name Status Preview Comments Updated (UTC)
overlay-kit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 13, 2024 1:25pm

@jungpaeng
Copy link
Member

Hi! Thank you for your interest in contributing to overlay-kit.

This looks good to me overall. One concern I have is that allowing arguments for unmount might cause some confusion when used together with close.

I'll take some time to think this over a bit more.

@XionWCFM
Copy link
Contributor Author

Hi! Thank you for your interest in contributing to overlay-kit.

This looks good to me overall. One concern I have is that allowing arguments for unmount might cause some confusion when used together with close.

I'll take some time to think this over a bit more.

I also agree that allowing unmount to resolve promises can cause confusion.

If so, how about thinking about this feature a little later?

I think I could suggest changing the unmount behavior so that it cannot resolve as before.

@XionWCFM XionWCFM changed the title feat: Added support for types in overlay.openAsync and unmount resolve support feat: Added support for types in overlay.openAsync Dec 13, 2024
@XionWCFM
Copy link
Contributor Author

I will close this PR. Thanks! @jungpaeng

@XionWCFM XionWCFM closed this Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants