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: pass all provides down to custom renderer #806

Merged

Conversation

alvarosabu
Copy link
Member

@alvarosabu alvarosabu commented Aug 27, 2024

Closes #537
Closes #732

This PR adds an opt-out bridge to pass down Vue parent provides down to the Tres components via TresCanvas with a flag to disable it enableProvideBridge

How to test

You should see console logs with prefixes like tres from the child tres component with the injects and vue for the vue child components, both should show a value different from undefined.

If you pass the :enable-provide-bridge="false" and refresh, the tres consoles should be undefined.

@alvarosabu alvarosabu requested a review from andretchen0 August 27, 2024 19:35
@alvarosabu alvarosabu self-assigned this Aug 27, 2024
Copy link

netlify bot commented Aug 27, 2024

Deploy Preview for tresjs-docs ready!

Name Link
🔨 Latest commit 5f689b7
🔍 Latest deploy log https://app.netlify.com/sites/tresjs-docs/deploys/66faa0ae0c32820008a9bd92
😎 Deploy Preview https://deploy-preview-806--tresjs-docs.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.

Copy link

pkg-pr-new bot commented Aug 27, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/@tresjs/core@806

commit: b1b2461

src/components/TresCanvas.vue Outdated Show resolved Hide resolved
Copy link
Contributor

@andretchen0 andretchen0 left a 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)

playground/.eslintrc-auto-import.json Outdated Show resolved Hide resolved
@alvarosabu alvarosabu marked this pull request as draft September 12, 2024 09:17
@alvarosabu
Copy link
Member Author

I grabbed the latest revision. provide from outside the doesn't seem to work on components within the – 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)

Hi @andretchen0 yeah no worries I was just trying stuff, will set this PR to draft.

I did manage to make it work with useTres and such but I can't make it work with reactivity. The inject inside just get the value the first time and it doesn't get updated further (for example clicking the button outside)

I'm currently clueless how to make it work, I opened a help request here in vue discord https://discord.com/channels/325477692906536972/1283405486175031418

@andretchen0
Copy link
Contributor

andretchen0 commented Sep 12, 2024

I'm currently clueless how to make it work

If we want to be explicit about provides that are "bridged", a component like this works:

<!-- 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>

@alvarosabu alvarosabu marked this pull request as ready for review September 27, 2024 13:13
src/components/TresCanvas.vue Outdated Show resolved Hide resolved
docs/api/tres-canvas.md Outdated Show resolved Hide resolved
@alvarosabu alvarosabu merged commit b4a3866 into main Sep 30, 2024
8 of 9 checks passed
@alvarosabu alvarosabu deleted the feature/732-pass-vue-providers-down-to-custom-renderer branch September 30, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Impossible to inject variable in canvas child component Unable to use custom provide inject
2 participants