Skip to content

Commit

Permalink
fix(types): use new createWithEqualityFn signature
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Apr 27, 2024
1 parent 0af41db commit f2de25c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
3 changes: 1 addition & 2 deletions packages/fiber/src/core/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export function useThree<T = RootState>(
selector: (state: RootState) => T = (state) => state as unknown as T,
equalityFn?: <T>(state: T, newState: T) => boolean,
): T {
// TODO: fix this type
return useStore()(selector, equalityFn as any)
return useStore()(selector, equalityFn)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/fiber/src/core/renderer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as THREE from 'three'
import * as React from 'react'
import { ConcurrentRoot } from 'react-reconciler/constants'
import { create } from 'zustand'
import { createWithEqualityFn } from 'zustand/traditional'

import type { Properties, ThreeElement } from '../three-types'
import {
Expand Down Expand Up @@ -569,7 +569,7 @@ function Portal({ state = {}, children, container }: PortalProps): JSX.Element {
})

const usePortalStore = React.useMemo(() => {
const store = create<RootState>((set, get) => ({ ...rest, set, get } as RootState))
const store = createWithEqualityFn<RootState>((set, get) => ({ ...rest, set, get } as RootState))

// Subscribe to previous root-state and copy changes over to the mirrored portal-state
const onMutate = (prev: RootState) => store.setState((state) => inject.current(prev, state))
Expand Down
7 changes: 4 additions & 3 deletions packages/fiber/src/core/store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as THREE from 'three'
import * as React from 'react'
import { create, type StoreApi, type UseBoundStore } from 'zustand'
import { type StoreApi } from 'zustand'
import { createWithEqualityFn, type UseBoundStoreWithEqualityFn } from 'zustand/traditional'
import type { DomEvent, EventManager, PointerCaptureTarget, ThreeEvent } from './events'
import { calculateDpr, type Camera, isOrthographicCamera, updateCamera } from './utils'
import type { FixedStage, Stage } from './stages'
Expand Down Expand Up @@ -154,15 +155,15 @@ export interface RootState {
internal: InternalState
}

export type RootStore = UseBoundStore<StoreApi<RootState>>
export type RootStore = UseBoundStoreWithEqualityFn<StoreApi<RootState>>

export const context = React.createContext<RootStore>(null!)

export const createStore = (
invalidate: (state?: RootState, frames?: number) => void,
advance: (timestamp: number, runGlobalEffects?: boolean, state?: RootState, frame?: XRFrame) => void,
): RootStore => {
const rootStore = create<RootState>((set, get) => {
const rootStore = createWithEqualityFn<RootState>((set, get) => {
const position = new THREE.Vector3()
const defaultTarget = new THREE.Vector3()
const tempTarget = new THREE.Vector3()
Expand Down
9 changes: 3 additions & 6 deletions packages/fiber/tests/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as THREE from 'three'
import { Instance, RootStore } from '../src'
import { createWithEqualityFn } from 'zustand/traditional'
import { type RootStore, type Instance } from '../src'
import {
is,
dispose,
Expand All @@ -16,11 +17,7 @@ import {
} from '../src/core/utils'

// Mocks a Zustand store
const storeMock = Object.assign(() => null!, {
getState: () => null!,
setState() {},
subscribe: () => () => {},
}) as unknown as RootStore
const storeMock = createWithEqualityFn(() => null!) satisfies RootStore

describe('is', () => {
const myFunc = () => null
Expand Down

0 comments on commit f2de25c

Please sign in to comment.