Skip to content

Find alternative to requiring extend() #24

@bigmistqke

Description

@bigmistqke

Potentially being able to shaketree is cool, but requiring extend(...) is a bit of a PITA.
Maybe we should think of a slightly different API.

Using T directly

you bail out of tree-shaking THREE, you can still extend with extend() but you are in it for the full ride in regards to loading THREE

import { T } from "solid-three"
return <T.Mesh/>

IIRC it is possible right now to extend the types via global declaration, so that you can type <T.CustomGuy/>
This would probably still be necessary if we want to support extending the global T.
We could also decide to have T be the easy-way, not allow extending it and just keep it as a wrapper around THREE.
If you want to extend what T can represent you will have to do export const { T } = createT({ ...THREE, NewGuy(...){...} }) like 👇

Using custom T via createT

You only load the subset that you pass in, either via its arguments.
createT would return { T, extend } allowing you to extend the proxy further.

import { createT } from "solid-three"
import { Mesh } from "three"

export const { T, extend } = createT({ Mesh })

Nice thing is then the types are scoped too, and are automatically inferred via the arguments.

Maybe we could have an additional generic for the extending types:

// index.ts
import { createT } from "solid-three"
import { Mesh } from "three"

export const { T, extend } = createT<{ MeshBasicMaterial }>({ Mesh })

// somewhere-else.ts
import { Mesh } from "three"
import { extend } from "./index.ts"
extend({ MeshBasicMaterial })

Metadata

Metadata

Assignees

No one assigned

    Labels

    nextIssues related to next pre-release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions