-
-
Notifications
You must be signed in to change notification settings - Fork 103
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: pass all provides down to custom renderer #806
base: main
Are you sure you want to change the base?
feat: pass all provides down to custom renderer #806
Conversation
✅ Deploy Preview for tresjs-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
commit: |
|
||
// Extract provides from the current instance and merge them | ||
if (currentInstance.provides) { | ||
Object.assign(provides, currentInstance.provides) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precedence is backwards here.
If you insert the following in an ancestor component of a TresCanvas
, it shouldn't shadow the TresCanvas
's own provide('useTres', ...)
:
provide('useTres', 'I should not break anything')
But it does shadow it and replaces the context.
I think this should be:
provides = Object.assign({}, provides, currentInstance.provides)
Or without the assign
:
const provided = new Set(['useTres', 'extends'])
[...]
for (const key of Object.keys(currentInstance.provides)) {
if (!provided.has(key)) {
provide(key, currentInstance.provides[key])
provided.add(key)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @alvarosabu ,
I grabbed the latest revision. provide
from outside the <TresCanvas>
doesn't seem to work on components within the <TresCanvas>
– I tried adding an inject
in SubComponentWithInject.vue
.
I could be wrong though. I didn't find a demo that showed how this is meant to be used, so I wrote a quick one, but maybe it's not how this is intended to be used. (I only found a demo that's intended to show that providing useTres
doesn't break things)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this file git add
ed by mistake maybe?
Hi @andretchen0 yeah no worries I was just trying stuff, will set this PR to draft. I did manage to make it work with I'm currently clueless how to make it work, I opened a help request here in vue discord https://discord.com/channels/325477692906536972/1283405486175031418 |
If we want to be explicit about <!-- ProvideBridge.vue -->
<script setup lang="ts">
import { provide } from 'vue'
interface Props {
keysValues: Record<string, any>
}
const props = withDefaults(defineProps<Props>(), {
keysValues: () => ({})
})
for (const [key, value] of Object.entries(props.keysValues)) {
provide(key, value)
}
</script>
<template>
<TresGroup>
<slot></slot>
</TresGroup>
</template> <TresCanvas>
<TresPerspectiveCamera />
<OrbitControls />
<ProvideBridge :keys-values="{ foo: inject('foo') }">
<Box /> <!-- Box can inject "foo" in its script setup -->
</ProvideBridge>
</TresCanvas> |
Closes #537
Closes #732