Comments (7)
Hey, thanks for taking the time, to read and response @alvarosabu, @andretchen0.
I'll definitely create some directives to address some of these methods (for example, v-layer, of course I'll open an issue first) but now I understand better the situation :)
from tres.
Or maybe I don't understand you
No problem. Maybe my answer wasn't clear. ;)
Do I understand this right?
<script setup>
const myCallback = e => {
// e here will be the actual function getObjectId, then I can do as I like for example
const myInnerMesh = e("myInnerObjectId")
}
</script>
<TresMesh :position="[-2, 2, 0]" :rotation="[0, Math.PI, 0]" :getObjectId="myCallback">
:field="value"
in a template normally means "bindvalue
tofield
" (declarative)- here, you're using it to mean, "call
value
and send it the actual value offield
" (imperative)
from tres.
Hey @JaimeTorrealba !
What do you think?
I think what you're proposing could be done behind the scenes. E.g., use a watcher to watch this prop and if it changes and if the value is a function, then call the function.
But for me, there's a conceptual mismatch with that pattern.
Vue templates, along with HTML/XML/etc. are declarative by design. They just describe. They aren't imperative and they don't have side effects in and of themselves.
If simpleLog
were immediately called here ...
<TresMesh :position="[-2, 2, 0]" :rotation="[0, Math.PI, 0]" :getObjectId="simpleLog">
... that would at least look imperative and like it's producing side effects.
For me, that's not the expected behavior. A DOM equivalent to your example would be:
<div onclick="simpleLog">
Like your example currently, just putting that in an HTML document doesn't execute simpleLog
. It just describes: "the onclick handler should be equal to simpleLog". It's up to the executing environment to execute the function when the user clicks or when the programmer triggers the click with JS.
from tres.
unmm, yes I know we can do that using template ref, But I'm not entire agree with your answer :). Or maybe I don't understand you
maybe "simpleLog" was not a good example lets call it "callback"
The way I see it we don't have side effects, ThreeJs comes with a lot of methods like clone, getObjectById, getWorldPosition, etc
Same way, the DOM has some methods in two. (I don't see how the onClick is equivalent to getObjectById)
I find, for example, a little annoying, to have to create a template ref for something like adding my mesh to a different layer.
in fact that doesn't work, maybe for #230
Why don't open the possibilty to have something like
<script setup>
const myCallback = e => { // e here will be the actual function getObjectId, then I can do as I like for example
const myInnerMesh = e(''myInnerObjectId")
}
</script>
<TresMesh :position="[-2, 2, 0]" :rotation="[0, Math.PI, 0]" :getObjectId="myCallback">
Same with others methods like clone or add?
from tres.
So any other alternative to this issue?
more directives?
from tres.
So any other alternative to this issue?
Afaik, the "blessed" way to do this in Vue is what you're already doing:
<script>
for interactivity and<template>
for declaring bindings.ref="..."
for moving from<template>
to<script>
.
Fwiw, I also get tired of typing out shallowRef
s, etc. But I find that reading random people's Vue SFC code is a lot easier than reading random people's straight JS code.
So I think there's good stuff in the "blessed" way of doing things. Even if it takes longer to write.
from tres.
Hey, @JaimeTorrealba thank you for opening this discussion, I find it really valuable and interesting.
Vue templates, along with HTML/XML/etc. are declarative by design. They just describe. They aren't imperative and they don't have side effects in and of themselves.
That would at least look imperative and like it's producing side effects.
I agree with @andretchen0 on this, passing a function through a prop is an antipattern in Vue, and since the goal of the library is to be a declarative solution using vue renderer this approach would kinda break that statement.
In Vue you pass data down you emit events up. React does allow pass functions down as prop by design.
One alternative would be to dynamically enable emits for the methods but this is done on the runtime
and not in the custom renderer, or as we initially thought, to detect if the instance[prop]
is a function and then pass the value as args of that function, but I guess @JaimeTorrealba for some cases you need the returned value right?
If the last question answer is yes, as @andretchen0 suggested, using refs
is the correct way forward. We could try emits or directives, but then you will have to create an individual directive for each function in the ecosystem of three.
from tres.
Related Issues (20)
- Cannot read properties of undefined (reading 'dispose') - GridHelper HOT 6
- `Camera` wrapped by `TresGroup` cannot be used properly after `version 4.0` HOT 2
- `Event` is not triggered in `TresGroup` HOT 2
- Impossible to `inject` variable in canvas child component HOT 4
- intersect only objects with events registered HOT 3
- No more outlines since V4 HOT 8
- TresInstancedMesh breaks with a dynamic instance count HOT 14
- Nested component not rendering HOT 2
- Deltatime Documentation Inaccuracy
- Rigged models are squished and broken HOT 3
- How to use vue-cli HOT 3
- Mesh that are delayed Join in the scene cannot trigger events HOT 4
- Sprite - Raycast events not firing if inside group HOT 5
- `TresPerspectiveCamera` `lookAt` not working with `CameraControls` HOT 3
- Recipe using `tweakpane`
- Events not registering on dynamically added objects HOT 2
- Library override the DPR setting in autonomy without chances to clamp / control it HOT 2
- Component: The setting parameter disableRender of TresCanvas is ineffective when renderMode is set to always. HOT 2
- Docs/playgrounds: change `ref(TresObject)` to `shallowRef(TresObject)` HOT 1
- When there is an annotated tag, the children of the scene will generate _Object3D model information HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tres.