Closed alvarosabu closed 6 months ago
Maybe @andretchen0 can you give me a hand with this one? The problem is here https://github.com/Tresjs/tres/blob/8efe6e00b7812a583e105ccb9429147f2d753585/src/core/nodeOps.ts#L197-L199. 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
@alvarosabu
Sure thing. I'll have a look!
Hey @alvarosabu !
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,
...
}
}
Would you like me to submit a PR?
Thanks @andretchen0 you are completely right, I just created the PR #602
Describe the bug
Seems like making
nodeOps
a function #579 broke primitiveobj
reactivity since we need to create a new element forprimitive
Reproduction
local
Steps to reproduce
No response
System Info
Used Package Manager
pnpm
Code of Conduct