Skip to content

Commit 95e4a7c

Browse files
coopbrihobbescodes
andauthored
Zustand 🐻 (#22)
* build(rdk,deps): add Zustand * build(deps): upgrade dependencies * refactor: migrate RDK state manager from React Context to Zustand * ci(changesets): add Zustand migration changeset * chore: format * fix: await backend registration * build(deps): upgrade dependencies * chore(biome): update schema version * chore: format * chore: format * build(deps): upgrade Three * docs(readme,getting-started): update session compatibility check location * build(deps,scripts): add Husky, prepare script, Biome check script * fix(biome): enable import sorting, remove redundant trailing `/**` * feature(code-quality,husky): run `biome check` on pre-commit * chore: format * chore(biome): reorder file includes patterns * chore: format * chore: remove store selection helpers * docs(apps,geolocation-demo,readme): add location services prompt * ci(changesets): update notes * refactor(store): `setReady` -> `setIsReady` * refactor(store): use fresh R3F context Three.js refs, remove redundant `isReady` state * chore(bun): update lock file * test(store): fix tests * ci(changesets): update notes * ci(changesets): update notes * ci(changesets): update notes * test(xr-session): remove type safety tests * build(deps,scripts): add Knip * refactor(types): generalize spatial computing types * ci(changesets): major -> minor * ci(changesets): remove non-export * docs(types,camera-source): update JSDoc * docs: update JSDoc * chore(types,context-value): removed unused `isReady` field * docs: update JSDoc * docs: update JSDoc * build(deps): upgrade React types * chore: update import * ci(changesets): condense changesets * ci(changesets): remove implementation details * ci(changesets): update notes * chore: remove unused deps * chore(code-quality,knip): add GitHub dir ignore pattern * build(scripts,test): `vitest` → `vitest run` * refactor(fiducial-backend): explicitly type internals * chore(rdk): adjust tsconfig to include test directory * docs: update JSDoc * chore: remove fragment Co-authored-by: hobbescodes <87732294+hobbescodes@users.noreply.github.com> * chore: remove fragment wrapper Co-authored-by: hobbescodes <87732294+hobbescodes@users.noreply.github.com> * chore: remove fragment wrapper Co-authored-by: hobbescodes <87732294+hobbescodes@users.noreply.github.com> * refactor(knip): remove test file globs from ignore pattern --------- Co-authored-by: hobbescodes <87732294+hobbescodes@users.noreply.github.com>
1 parent 1ef322c commit 95e4a7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1017
-444
lines changed

.changeset/goofy-zebras-hope.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
"@omnidotdev/rdk": minor
3+
---
4+
5+
Migrated the RDK state manager from React Context to Zustand for better performance, flexibility, and access outside of React contexts.
6+
7+
**Breaking Changes:**
8+
9+
- Replaced `XRContext` and `useXR` hook with Zustand store (`useXRStore`)
10+
- Renamed types
11+
- `XRBackend``Backend`
12+
- `XRContextValue``ContextValue`
13+
14+
**New Library Exports:**
15+
16+
- `useXRStore`: Main Zustand store hook for full state access
17+
- `getXRStore`: Non-React access to store state
18+
- `subscribeToXRStore`: Non-React subscription to store changes
19+
- `XRStore`, `XRStoreState`, `XRStoreActions`: TypeScript types
20+
21+
**Migration Guide:**
22+
23+
Replace `useXR()` with direct store selectors:
24+
25+
- `useXR().camera``useXRStore((state) => state.camera)`
26+
- `useXR().backends``useXRStore((state) => state.backends)`
27+
- Full store access: `useXRStore()` or `useXRStore(selector)`
28+
29+
Replace types:
30+
31+
- `XRBackend``Backend`
32+
- `XRContextValue``ContextValue`

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bun check --staged --no-errors-on-unmatched

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ If you want to add a new XR module to be orchestrated by the overarching RDK API
7171

7272
1. Create `packages/rdk/src/[moduleName]`
7373
2. Export the module files from `packages/rdk/src/index.ts`
74-
3. If needed, add session compatibility checks to `XRSessionProvider`
74+
3. If needed, add session compatibility checks to the XR store
7575

7676
See the `fiducial/` and `geolocation/` modules for reference implementations.
7777

apps/fiducial-demo/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"dependencies": {
2727
"@ar-js-org/ar.js": "^3.4.7",
2828
"@omnidotdev/rdk": "workspace:*",
29-
"@react-three/drei": "^10.7.6",
3029
"@react-three/fiber": "^9.4.0",
3130
"react": "^19.2.0",
3231
"react-dom": "^19.2.0",

apps/fiducial-demo/src/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { XR, FiducialAnchor, FiducialSession } from "@omnidotdev/rdk";
1+
import { FiducialAnchor, FiducialSession, XR } from "@omnidotdev/rdk";
22
import { Canvas } from "@react-three/fiber";
3-
43
import { Supertorus } from "components";
54

65
/**

apps/geolocation-demo/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ bun preview
3838

3939
- **HTTPS Required**: Geolocation API requires a secure context (HTTPS) for production use
4040
- **Location Permission**: Browser will prompt for location access
41+
- Make sure location services are enabled at the device level
4142
- **GPS Accuracy**: Works best outdoors with clear sky view
4243
- **Mobile-First**: Optimized for mobile AR experiences
4344

apps/geolocation-demo/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
},
2626
"dependencies": {
2727
"@omnidotdev/rdk": "workspace:*",
28-
"@react-three/drei": "^10.7.6",
2928
"@react-three/fiber": "^9.4.0",
3029
"locar": "^0.1.4",
3130
"react": "^19.2.0",

apps/geolocation-demo/src/App.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { XR, GeolocationSession, GeolocationAnchor } from "@omnidotdev/rdk";
1+
import { GeolocationAnchor, GeolocationSession, XR } from "@omnidotdev/rdk";
22
import { Canvas } from "@react-three/fiber";
3-
4-
import { GPSPin, Landmark, Compass } from "components";
3+
import { Compass, GPSPin, Landmark } from "components";
54

65
// set these to your preferred location
76
const BASE_LATITUDE = 48.68951980519457,

apps/geolocation-demo/src/components/Compass.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useRef } from "react";
21
import { useFrame } from "@react-three/fiber";
2+
import { useRef } from "react";
3+
34
import type * as THREE from "three";
45

56
interface CompassProps {

apps/geolocation-demo/src/components/GPSPin.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useRef } from "react";
21
import { useFrame } from "@react-three/fiber";
2+
import { useRef } from "react";
3+
34
import type * as THREE from "three";
45

56
interface GPSPinProps {

0 commit comments

Comments
 (0)