Skip to content

Add API to initialize null-initialized properties? #38

@bigmistqke

Description

@bigmistqke

Currently this will fail:

return <Canvas scene={{ background: [1, 0, 0] }} />`
  • When encountering an array, the prop handling will try to target[propName].set(...propValue)
  • Because Scene.background is null initialized, there is nothing to .set to

The current solution is to pass a THREE.Color instead:

return <Canvas scene={{ background: new Color(1, 0, 0) }} />`

But maybe there could be a way to declare

  • if prop[key] exists 👉 prop[key].set(...values)
  • if prop[key] exists 👉 prop[key] = new Constructor(...values)

Proposal

Maybe something like:

<Canvas scene={{ background: setOrInit(Color, [1, 0, 0]) }} />

a bit in the vein of https://github.com/tc39/proposal-upsert ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions