|
1 | 1 | import * as THREE from 'three'
|
2 | 2 | import * as React from 'react'
|
3 |
| -import create, { GetState, SetState, StoreApi, UseBoundStore } from 'zustand' |
| 3 | +import create, { StoreApi, UseBoundStore } from 'zustand' |
4 | 4 | import { DomEvent, EventManager, PointerCaptureTarget, ThreeEvent } from './events'
|
5 | 5 | import { calculateDpr, Camera, isOrthographicCamera, prepare, updateCamera } from './utils'
|
6 | 6 | import { FixedStage, Stage } from './stages'
|
@@ -28,7 +28,7 @@ export interface Intersection extends THREE.Intersection {
|
28 | 28 | export type Subscription = {
|
29 | 29 | ref: React.MutableRefObject<RenderCallback>
|
30 | 30 | priority: number
|
31 |
| - store: UseBoundStore<RootState, StoreApi<RootState>> |
| 31 | + store: RootStore |
32 | 32 | }
|
33 | 33 |
|
34 | 34 | export type Dpr = number | [min: number, max: number]
|
@@ -89,18 +89,14 @@ export type InternalState = {
|
89 | 89 | render: 'auto' | 'manual'
|
90 | 90 | /** The max delta time between two frames. */
|
91 | 91 | maxDelta: number
|
92 |
| - subscribe: ( |
93 |
| - callback: React.MutableRefObject<RenderCallback>, |
94 |
| - priority: number, |
95 |
| - store: UseBoundStore<RootState, StoreApi<RootState>>, |
96 |
| - ) => () => void |
| 92 | + subscribe: (callback: React.MutableRefObject<RenderCallback>, priority: number, store: RootStore) => () => void |
97 | 93 | }
|
98 | 94 |
|
99 | 95 | export type RootState = {
|
100 | 96 | /** Set current state */
|
101 |
| - set: SetState<RootState> |
| 97 | + set: StoreApi<RootState>['setState'] |
102 | 98 | /** Get current state */
|
103 |
| - get: GetState<RootState> |
| 99 | + get: StoreApi<RootState>['getState'] |
104 | 100 | /** The instance of the renderer */
|
105 | 101 | gl: THREE.WebGLRenderer
|
106 | 102 | /** Default camera */
|
@@ -156,17 +152,19 @@ export type RootState = {
|
156 | 152 | /** When the canvas was clicked but nothing was hit */
|
157 | 153 | onPointerMissed?: (event: MouseEvent) => void
|
158 | 154 | /** If this state model is layerd (via createPortal) then this contains the previous layer */
|
159 |
| - previousRoot?: UseBoundStore<RootState, StoreApi<RootState>> |
| 155 | + previousRoot?: RootStore |
160 | 156 | /** Internals */
|
161 | 157 | internal: InternalState
|
162 | 158 | }
|
163 | 159 |
|
164 |
| -const context = React.createContext<UseBoundStore<RootState>>(null!) |
| 160 | +export type RootStore = UseBoundStore<StoreApi<RootState>> |
| 161 | + |
| 162 | +const context = React.createContext<RootStore>(null!) |
165 | 163 |
|
166 | 164 | const createStore = (
|
167 | 165 | invalidate: (state?: RootState, frames?: number) => void,
|
168 | 166 | advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState, frame?: XRFrame) => void,
|
169 |
| -): UseBoundStore<RootState> => { |
| 167 | +): RootStore => { |
170 | 168 | const rootStore = create<RootState>((set, get) => {
|
171 | 169 | const position = new THREE.Vector3()
|
172 | 170 | const defaultTarget = new THREE.Vector3()
|
@@ -311,11 +309,7 @@ const createStore = (
|
311 | 309 | render: 'auto',
|
312 | 310 | maxDelta: 1 / 10,
|
313 | 311 | priority: 0,
|
314 |
| - subscribe: ( |
315 |
| - ref: React.MutableRefObject<RenderCallback>, |
316 |
| - priority: number, |
317 |
| - store: UseBoundStore<RootState, StoreApi<RootState>>, |
318 |
| - ) => { |
| 312 | + subscribe: (ref: React.MutableRefObject<RenderCallback>, priority: number, store: RootStore) => { |
319 | 313 | const state = get()
|
320 | 314 | const internal = state.internal
|
321 | 315 | // If this subscription was given a priority, it takes rendering into its own hands
|
|
0 commit comments