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

fix: proxy app context #394

Merged
merged 12 commits into from
Sep 11, 2023
Prev Previous commit
Next Next commit
fix: object assign approach for inner app context
  • Loading branch information
alvarosabu committed Sep 11, 2023
commit 3a6dc317c39cba6b2ebcdcf372eb8ccd6676ef2e
15 changes: 12 additions & 3 deletions src/components/TresCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,22 @@ const slots = defineSlots<{
default(): any
}>()

const vueApp = getCurrentInstance()?.appContext.app
const instance = getCurrentInstance()!

const createInternalComponent = (context: TresContext) =>
defineComponent({
setup() {
const ctx = getCurrentInstance()?.appContext
if (ctx) ctx.app = vueApp as App
const inner = getCurrentInstance()!

Object.assign(inner.appContext, instance.appContext)
//@ts-expect-error: internal property
Object.assign(inner.provides, inner.appContext.provides)
if (import.meta.env.DEV) {
//@ts-expect-error: internal property
inner.appContext.reload = () => {
mountCustomRenderer(context)
}
}
provide('useTres', context)
provide('extend', extend)
return () => h(Fragment, null, slots?.default ? slots.default() : [])
Expand Down
Loading