Skip to content

Refactor useTresContextProvider into createInjectionState #961

@alvarosabu

Description

@alvarosabu

Description

As a maintainer of TresJS, I would like to clean up the core logic by refactoring it to use VueUse createInjectionState https://vueuse.org/shared/createInjectionState/#createinjectionstate instead

Suggested solution

Replace manual context provider with something like:

const [useTresContextProvider, useTresContext] = createInjectionState((props, emit) => {
    // Create refs with initial null values
  const scene = shallowRef<TresScene | null>(null)
  const renderer = shallowRef<WebGLRenderer | null>(null)
  const camera = shallowRef<PerspectiveCamera | null>(null)
  const loop = createRenderLoop()

   // Render mode logic etc
})

export { useTresContext, useTresContextProvider }

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

Labels

p3-significantHigh-priority enhancement (priority)v5

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions