From 76c5061bea4c124f55fe3fceed7ba38a64fe4fa1 Mon Sep 17 00:00:00 2001 From: Antoine BERNIER Date: Sun, 17 Nov 2024 11:34:16 +0100 Subject: [PATCH] chore: zustand 5 (#2212) * zustand 4 * zustand 5 --- package.json | 2 +- src/core/Progress.tsx | 2 +- src/web/KeyboardControls.tsx | 10 ++++++---- src/web/Select.tsx | 2 +- yarn.lock | 23 ++++++++++++++++++++++- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index b573ec9c9..b82cdf7d8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/core/Progress.tsx b/src/core/Progress.tsx index aae8939aa..45152ab7d 100644 --- a/src/core/Progress.tsx +++ b/src/core/Progress.tsx @@ -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[] diff --git a/src/web/KeyboardControls.tsx b/src/web/KeyboardControls.tsx index 8b8b7b3d8..fc2f6f9f9 100644 --- a/src/web/KeyboardControls.tsx +++ b/src/web/KeyboardControls.tsx @@ -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 @@ -48,7 +48,7 @@ type KeyboardControlsProps = { type KeyboardControlsApi = [ StoreApiWithSubscribeWithSelector>['subscribe'], StoreApiWithSubscribeWithSelector>['getState'], - UseBoundStore>, + UseBoundStore>>, ] const context = /* @__PURE__ */ React.createContext(null!) @@ -56,8 +56,10 @@ const context = /* @__PURE__ */ React.createContext(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( - 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( diff --git a/src/web/Select.tsx b/src/web/Select.tsx index 709995321..1d33eb8ff 100644 --- a/src/web/Select.tsx +++ b/src/web/Select.tsx @@ -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([]) diff --git a/yarn.lock b/yarn.lock index a9a936f0b..5446c401f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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