@sqlrooms/room-store 0.26.0-rc.6 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -36
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -14,10 +14,12 @@ The `RoomStore` is a Zustand store that holds the entire state of a room. It is
|
|
|
14
14
|
|
|
15
15
|
### RoomState
|
|
16
16
|
|
|
17
|
-
The `RoomState` is the object that defines the shape of the store. It
|
|
17
|
+
The `RoomState` is the object that defines the shape of the store. It includes state from the base room shell slice and any additional slices you add:
|
|
18
18
|
|
|
19
|
-
- `config`: This holds the configuration of the room that is persisted. This is defined by a `zod` schema, often extending the `BaseRoomConfig` from `@sqlrooms/room-config`.
|
|
19
|
+
- `room.config`: This holds the configuration of the room that is persisted. This is defined by a `zod` schema, often extending the `BaseRoomConfig` from `@sqlrooms/room-config`.
|
|
20
20
|
- `room`: This holds the client-side state of the room, such as task progress, and provides actions for interacting with the room.
|
|
21
|
+
- `db`: DuckDB database state and methods
|
|
22
|
+
- `layout`: Layout configuration and panel definitions
|
|
21
23
|
|
|
22
24
|
### Slices
|
|
23
25
|
|
|
@@ -31,53 +33,49 @@ Here's an example of how to create a room store with a custom feature slice.
|
|
|
31
33
|
import {
|
|
32
34
|
createRoomStore,
|
|
33
35
|
createRoomShellSlice,
|
|
34
|
-
|
|
36
|
+
RoomShellSliceState,
|
|
35
37
|
} from '@sqlrooms/room-store';
|
|
36
|
-
import {BaseRoomConfig} from '@sqlrooms/room-config';
|
|
37
|
-
import {z} from 'zod';
|
|
38
38
|
import {StateCreator} from 'zustand';
|
|
39
39
|
|
|
40
|
-
// 1. Define
|
|
41
|
-
// This extends the base config with a custom property.
|
|
42
|
-
export const MyRoomConfig = BaseRoomConfig.extend({
|
|
43
|
-
defaultChartType: z.enum(['bar', 'line', 'scatter']).default('bar'),
|
|
44
|
-
});
|
|
45
|
-
export type MyRoomConfig = z.infer<typeof MyRoomConfig>;
|
|
46
|
-
|
|
47
|
-
// 2. Define the state and actions for your custom feature slice.
|
|
40
|
+
// 1. Define the state and actions for your custom feature slice.
|
|
48
41
|
export interface MyFeatureSlice {
|
|
49
42
|
activeChartId: string | null;
|
|
50
43
|
setActiveChartId: (id: string | null) => void;
|
|
51
44
|
}
|
|
52
45
|
|
|
53
|
-
//
|
|
46
|
+
// 2. Create your custom slice.
|
|
54
47
|
export const createMyFeatureSlice: StateCreator<MyFeatureSlice> = (set) => ({
|
|
55
48
|
activeChartId: null,
|
|
56
49
|
setActiveChartId: (id) => set({activeChartId: id}),
|
|
57
50
|
});
|
|
58
51
|
|
|
59
|
-
//
|
|
52
|
+
// 3. Define the full state of your room, combining the base RoomShellSliceState
|
|
60
53
|
// with your custom slice's state.
|
|
61
|
-
export type MyRoomState =
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
export const {roomStore, useRoomStore} = createRoomStore<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}))
|
|
54
|
+
export type MyRoomState = RoomShellSliceState & MyFeatureSlice;
|
|
55
|
+
|
|
56
|
+
// 4. Create the room store by composing the base slice and your custom slice.
|
|
57
|
+
export const {roomStore, useRoomStore} = createRoomStore<MyRoomState>(
|
|
58
|
+
(set, get, store) => ({
|
|
59
|
+
...createRoomShellSlice({
|
|
60
|
+
config: {
|
|
61
|
+
// You can provide initial values for your config here
|
|
62
|
+
title: 'My First Room',
|
|
63
|
+
dataSources: [],
|
|
64
|
+
},
|
|
65
|
+
layout: {
|
|
66
|
+
config: {
|
|
67
|
+
// Layout configuration
|
|
68
|
+
},
|
|
69
|
+
panels: {
|
|
70
|
+
// Panel definitions
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
})(set, get, store),
|
|
74
|
+
|
|
75
|
+
// Add your custom slice to the store
|
|
76
|
+
...createMyFeatureSlice(set, get, store),
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
81
79
|
|
|
82
80
|
export {roomStore, useRoomStore};
|
|
83
81
|
```
|
|
@@ -107,7 +105,7 @@ You can use the `useRoomStore` hook returned by `createRoomStore` to access the
|
|
|
107
105
|
import {useRoomStore} from './my-room-store';
|
|
108
106
|
|
|
109
107
|
function RoomTitle() {
|
|
110
|
-
const title = useRoomStore((state) => state.config.title);
|
|
108
|
+
const title = useRoomStore((state) => state.room.config.title);
|
|
111
109
|
const activeChartId = useRoomStore((state) => state.activeChartId);
|
|
112
110
|
const setActiveChartId = useRoomStore((state) => state.setActiveChartId);
|
|
113
111
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/room-store",
|
|
3
|
-
"version": "0.26.0
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@sqlrooms/room-config": "0.26.0
|
|
21
|
+
"@sqlrooms/room-config": "0.26.0",
|
|
22
22
|
"immer": "^10.1.3",
|
|
23
23
|
"zod": "^4.1.8",
|
|
24
24
|
"zustand": "^5.0.8"
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"typecheck": "tsc --noEmit",
|
|
34
34
|
"typedoc": "typedoc"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "3376e76ddfa3c54097b79a20b88a1c37814dca61"
|
|
37
37
|
}
|