Git Product home page Git Product logo

Comments (7)

JaimeTorrealba avatar JaimeTorrealba commented on August 12, 2024 2

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.

andretchen0 avatar andretchen0 commented on August 12, 2024 1

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 "bind value to field" (declarative)
  • here, you're using it to mean, "call value and send it the actual value of field" (imperative)

from tres.

andretchen0 avatar andretchen0 commented on August 12, 2024

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.

JaimeTorrealba avatar JaimeTorrealba commented on August 12, 2024

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.

https://play.tresjs.org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pUaAWfx+89NvucvWzFgTffeE83rdj/psq7TM7To77gm9/AFxrnho=

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.

JaimeTorrealba avatar JaimeTorrealba commented on August 12, 2024

So any other alternative to this issue?
more directives?

from tres.

andretchen0 avatar andretchen0 commented on August 12, 2024

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 shallowRefs, 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.

alvarosabu avatar alvarosabu commented on August 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.