Skip to content

Commit

Permalink
chore: zustand 5 (#2212)
Browse files Browse the repository at this point in the history
* zustand 4

* zustand 5
  • Loading branch information
abernier authored Nov 17, 2024
1 parent d63e063 commit 76c5061
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"tunnel-rat": "^0.1.2",
"utility-types": "^3.11.0",
"uuid": "^9.0.1",
"zustand": "^3.7.1"
"zustand": "^5.0.1"
},
"devDependencies": {
"@babel/core": "^7.26.0",
Expand Down
2 changes: 1 addition & 1 deletion src/core/Progress.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { DefaultLoadingManager } from 'three'
import create from 'zustand'
import { create } from 'zustand'

type Data = {
errors: string[]
Expand Down
10 changes: 6 additions & 4 deletions src/web/KeyboardControls.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import create, { StoreApi, UseBoundStore } from 'zustand'
import { create, StoreApi, UseBoundStore } from 'zustand'
import { subscribeWithSelector } from 'zustand/middleware'

// These are removed in Zustand v4
Expand Down Expand Up @@ -48,16 +48,18 @@ type KeyboardControlsProps = {
type KeyboardControlsApi<T extends string = string> = [
StoreApiWithSubscribeWithSelector<KeyboardControlsState<T>>['subscribe'],
StoreApiWithSubscribeWithSelector<KeyboardControlsState<T>>['getState'],
UseBoundStore<KeyboardControlsState<T>>,
UseBoundStore<StoreApi<KeyboardControlsState<T>>>,
]

const context = /* @__PURE__ */ React.createContext<KeyboardControlsApi>(null!)

export function KeyboardControls({ map, children, onChange, domElement }: KeyboardControlsProps) {
const key = map.map((item) => item.name + item.keys).join('-')
const useControls = React.useMemo(() => {
return create<KeyboardControlsState>(
subscribeWithSelector(() => map.reduce((prev, cur) => ({ ...prev, [cur.name]: false }), {}))
return create(
subscribeWithSelector(() =>
map.reduce((prev, cur) => ({ ...prev, [cur.name]: false }), {} as KeyboardControlsState)
)
)
}, [key])
const api: KeyboardControlsApi = React.useMemo(
Expand Down
2 changes: 1 addition & 1 deletion src/web/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react'
import * as THREE from 'three'
import { SelectionBox } from 'three-stdlib'
import { useThree } from '@react-three/fiber'
import shallow from 'zustand/shallow'
import { shallow } from 'zustand/shallow'

const context = /* @__PURE__ */ React.createContext<THREE.Object3D[]>([])

Expand Down
23 changes: 22 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2905,7 +2905,7 @@ __metadata:
uuid: "npm:^9.0.1"
vite: "npm:^5.4.11"
vite-plugin-glslify: "npm:^2.1.0"
zustand: "npm:^3.7.1"
zustand: "npm:^5.0.1"
peerDependencies:
"@react-three/fiber": ">=8.0"
react: ">=18.0"
Expand Down Expand Up @@ -13315,3 +13315,24 @@ __metadata:
checksum: 10c0/de507f09eb79039d74d282df6ffac6c7fb6b840ca3620b0392bcbe3f9049902802db5448b4002e6fcb32f903f7ec1aea14602049eb2a3a8410bfea7186d72fb7
languageName: node
linkType: hard

"zustand@npm:^5.0.1":
version: 5.0.1
resolution: "zustand@npm:5.0.1"
peerDependencies:
"@types/react": ">=18.0.0"
immer: ">=9.0.6"
react: ">=18.0.0"
use-sync-external-store: ">=1.2.0"
peerDependenciesMeta:
"@types/react":
optional: true
immer:
optional: true
react:
optional: true
use-sync-external-store:
optional: true
checksum: 10c0/b4239c8bf3988bfdaaed1c48f3958d0b047b721c4908a76bd78e73387d107963cda774541cf303c2ea89261481c995aa6666e7e77c30717ad440cdb499d9e5ca
languageName: node
linkType: hard

0 comments on commit 76c5061

Please sign in to comment.