Skip to content

Commit f0f7cc0

Browse files
committed
Feat: exposed actions to retrive state as well as the underlying redix store
1 parent 28450a4 commit f0f7cc0

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/actions/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { panDown, panLeft, panRight, panUp } from "@/components/workspace/zoom";
22
import { store } from "@/store";
3-
import { clearElements, deselectElement } from "@/store/reducers/editor";
3+
import { clearElements, deselectElement, selectElement } from "@/store/reducers/editor";
4+
import { stateToJSON } from "@/utils";
45

5-
export const actions = {
6+
const actions = {
7+
selectElement: (elementId: string) => store.dispatch(selectElement(elementId)),
68
deselectElement: (elementId: string) => store.dispatch(deselectElement(elementId)),
79
deselectAllElements: () => store.dispatch(clearElements(false)),
10+
getState: stateToJSON,
811
panLeft,
912
panDown,
1013
panRight,
1114
panUp
1215
};
1316

17+
export { store, actions };
18+
1419
export default actions;

src/stories/modifying-state.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Meta } from "@storybook/blocks";
2+
3+
<Meta title="Modifying State" />
4+
5+
<h1>Modifying State</h1>
6+
7+
<h4>React Seat Toolkit uses Redux to manage its state. You can modify its state using the underlying `store` itself or a couple of abstracted `actions` which are available to you.</h4>
8+
9+
<h4>Here is an example of how you can deselect a seat manually and retrieve the updated state:</h4>
10+
11+
```tsx
12+
import { actions } from "@mezh-hq/react-seat-toolkit";
13+
14+
actions.deselectElement("<seat-id>");
15+
16+
const state = actions.getState();
17+
18+
console.log(state); // Updated workspace state of type STKData
19+
```
20+
21+
<h4>Here is an example of how you can import and use the `store` to retrieve the current Redux state:</h4>
22+
23+
```tsx
24+
import { store } from "@mezh-hq/react-seat-toolkit";
25+
26+
const state = store.getState();
27+
28+
console.log(state); // Current redux state (Not of type STKData)
29+
```
30+
31+
<h4>For a full list of supported actions please have a look at its type definitions</h4>

0 commit comments

Comments
 (0)