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: experimental composition api via useEvent() ans async context support #1546

Merged
merged 8 commits into from
Aug 7, 2023

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Aug 7, 2023

πŸ”— Linked issue

❓ 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

This PR enables a new experiment using unctx native local storage support to enable a new development pattern similar to vue composition API to make server events available in every async context using useEvent() without need to passing it directly around.

Before:

// routes/index.ts
export default defineEventHandler(async (event) => {
  const user = await useAuth(event)
})

// utils/auth.ts
export function useAuth(event) {
  return useSession(event)
}

After:

// routes/index.ts
export default defineEventHandler(async () => {
  const user = await useAuth()
})

// utils/auth.ts
export function useAuth() {
  return useSession()
}

Note: This feature is currently supported for Node.js environments.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pi0 pi0 requested a review from danielroe August 7, 2023 12:32
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

Looks πŸ‘Œ

@nuxt-studio
Copy link
Contributor

nuxt-studio bot commented Aug 7, 2023

βœ… Live Preview ready!

Name Edit Preview Latest Commit
nitro Edit on Studio β†—οΈŽ View Live Preview 94ba884

@pi0 pi0 changed the title feat: experimental composition api via useEvent(), unctx and async local storage feat: experimental composition api via useEvent() ans async context support Aug 7, 2023
@codecov
Copy link

codecov bot commented Aug 7, 2023

Codecov Report

Merging #1546 (94ba884) into main (346a61a) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1546      +/-   ##
==========================================
- Coverage   76.38%   76.35%   -0.03%     
==========================================
  Files          73       73              
  Lines        7550     7558       +8     
  Branches      745      744       -1     
==========================================
+ Hits         5767     5771       +4     
- Misses       1782     1785       +3     
- Partials        1        2       +1     
Files Changed Coverage Ξ”
src/imports.ts 100.00% <100.00%> (ΓΈ)
src/rollup/config.ts 89.77% <100.00%> (-0.80%) ⬇️
src/types/global.ts 100.00% <100.00%> (ΓΈ)
src/types/nitro.ts 100.00% <100.00%> (ΓΈ)

@pi0 pi0 marked this pull request as ready for review August 7, 2023 14:55
@pi0 pi0 merged commit 6669fb2 into main Aug 7, 2023
8 checks passed
@pi0 pi0 deleted the feat/exp-als branch August 7, 2023 14:57
@pi0 pi0 mentioned this pull request Aug 21, 2023
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