Giter Site home page Giter Site logo

Comments (4)

alvarosabu avatar alvarosabu commented on June 23, 2024 1

Thanks @andretchen0 you are completely right, I just created the PR #602

from tres.

alvarosabu avatar alvarosabu commented on June 23, 2024

Maybe @andretchen0 can you give me a hand with this one? The problem is here

tres/src/core/nodeOps.ts

Lines 197 to 199 in 8efe6e0

const newInstance = nodeOps.createElement('primitive', undefined, undefined, {
object: nextValue,
})
. This features is a key one for v4

I was trying to avoid needing to duplicate the code inside of createElement, but now that nodeOps is a function, this is no longer correct.

Let me know

from tres.

andretchen0 avatar andretchen0 commented on June 23, 2024

@alvarosabu

Sure thing. I'll have a look!

from tres.

andretchen0 avatar andretchen0 commented on June 23, 2024

Hey @alvarosabu !

Fix

One approach to this would be to define the functions and then collect them into an object to return.

Concretely, right now nodeOps looks like ...

export const nodeOps: () => RendererOptions<TresObject, TresObject | null> = () => {
  let scene: TresScene | null = null

  // NOTE: functions are defined in the return object
  return { createElement(tag, _isSVG, _anchor, props): TresObject | null {
    if (!props) props = {}

    if (!props.args) {
      props.args = []
    }

But if it's like the following, then you can call createElement( ... ) from within any function that's defined after.

export const nodeOps: () => RendererOptions<TresObject, TresObject | null> = () => {
  let scene: TresScene | null = null

  // NOTE: createElement, etc. are still defined within the nodeOps function, so they close over scene
  const createElement(tag, _isSVG, _anchor, props): TresObject | null => { ... }
  
  const patchProp(node, prop, prevValue, nextValue) => { ... 
    ...
    // NOTE: patchProp now closes over createElement, so you can call it like so ...
    const newInstance = createElement('primitive', undefined, undefined, { ...
    ...
  }
  
  // NOTE: assemble the `RendererOptions` object and return it.
  return {
   createElement,
   patchProp,
   ...
  }
}

Question

Would you like me to submit a PR?

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.