Skip to content

feat(nuxt): add clear function to async data #26259

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

Merged
merged 9 commits into from
Mar 17, 2024
Merged

Conversation

DamianGlowala
Copy link
Member

@DamianGlowala DamianGlowala commented Mar 14, 2024 β€’

πŸ”— Linked issue

resolves #26195

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Allows clearing Nuxt data from within the async data composable (hence removing a need for knowing and/or passing a key). Original issue describes resetting Nuxt data instead (by respecting the optional default prop rather than always setting data.value to undefined). Thought this might be better to start with though; I'm open to any suggestions!

Will update the docs knowing this is a desirable addition.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have added tests (if possible).
  • I have updated the documentation accordingly.

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
danielroe Daniel Roe
@DamianGlowala DamianGlowala self-assigned this Mar 14, 2024
Copy link

stackblitz bot commented Mar 14, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

autofix-ci bot and others added 2 commits March 14, 2024 23:14

Verified

This commit was signed with the committer’s verified signature.
danielroe Daniel Roe

Verified

This commit was signed with the committer’s verified signature.
danielroe Daniel Roe
@TheAlexLichter
Copy link
Member

Seems like a nice DX improvement to me πŸ‘

With regards to clear (undefined) vs. reset (set to default value) - I was wondering if we need a distinction or could rely on resetting it to the default value straight away. But if that should be consistent, clearNuxtData should behave the same way, which would be tricky at the moment πŸ€”

@DamianGlowala
Copy link
Member Author

I certainly agree - this raises a question whether clearNuxtData should respect the default value. We have a couple of options:

  • make clearNuxtData respect the default value (I personally prefer this behavior; would be a breaking change though)
  • add reset function to async data which would differ from clear (setting it to the default value vs undefined)
  • add optional param to clear function which would allow either reverting to the default value or not (again, some could ask why we wouldn't have the same param for clearNuxtData)

@TheAlexLichter
Copy link
Member

I think both, clear and reset, might be confusing

Maybe updating it for v4 could be nice? πŸ€”

@DamianGlowala
Copy link
Member Author

They will be confusing, I'm sure.

Created #26269 to discuss updating it for v4.

Copy link
Contributor

nuxt-studio bot commented Mar 16, 2024

βœ… Live Preview ready!

Name Edit Preview Latest Commit
Nuxt Docs Edit on Studio β†—οΈŽ View Live Preview 4eeaac1

@danielroe danielroe merged commit 02d6838 into main Mar 17, 2024
34 of 36 checks passed
@danielroe danielroe deleted the feat/async-data-clear-fn branch March 17, 2024 00:19
This was referenced Mar 17, 2024
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.

Add reset fn to data fetching composables
3 participants