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

Run hooks and props within the context of the vue app #448

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

pleek91
Copy link
Contributor

@pleek91 pleek91 commented Jan 30, 2025

Description

Since 3.3 vue has had a utility called runWithContext which allows for global injection to work within any callback. Using this when running hooks and props means that global injection also works within those callback.

import { inject } from 'vue'

router.onAfterRouteEnter((to, context) => {
  const value = inject('global')

  ...
})
import { inject } from 'vue'

const route = createRoute({
  ...
}, async (route) => {
  const value = inject('global')

  return { value }
})

@pleek91 pleek91 added the enhancement New feature or request label Jan 30, 2025
Copy link

netlify bot commented Jan 30, 2025

Deploy Preview for kitbag-router ready!

Name Link
🔨 Latest commit e29c7e4
🔍 Latest deploy log https://app.netlify.com/sites/kitbag-router/deploys/679ad0dbfd69f9000828368c
😎 Deploy Preview https://deploy-preview-448--kitbag-router.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +314 to +316
vueApp = app

propStore.setVueApp(app)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is overkill but thoughts on storing the vueApp in it's own "store"? That would solve 2 things I don't love about the current implementation.

  1. we use a let
  2. the hooks and props technically have independent references and ideally they'd look in the same place

Copy link
Contributor

Choose a reason for hiding this comment

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

that new "store" could also be responsible for exporting the runWithContext piece

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't hate it, I'll look into that tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stackoverfloweth looking at this again not sure how the new store would work. We don't really have a way for the propsStore to get something from a separate store. Maybe we can chat about this

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

Successfully merging this pull request may close these issues.

2 participants