Skip to content

Commit

Permalink
Feat: exposed actions to retrive state as well as the underlying redi…
Browse files Browse the repository at this point in the history
…x store
  • Loading branch information
Akalanka47000 committed Aug 7, 2024
1 parent 28450a4 commit f0f7cc0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { panDown, panLeft, panRight, panUp } from "@/components/workspace/zoom";
import { store } from "@/store";
import { clearElements, deselectElement } from "@/store/reducers/editor";
import { clearElements, deselectElement, selectElement } from "@/store/reducers/editor";
import { stateToJSON } from "@/utils";

export const actions = {
const actions = {
selectElement: (elementId: string) => store.dispatch(selectElement(elementId)),
deselectElement: (elementId: string) => store.dispatch(deselectElement(elementId)),
deselectAllElements: () => store.dispatch(clearElements(false)),
getState: stateToJSON,
panLeft,
panDown,
panRight,
panUp
};

export { store, actions };

export default actions;
31 changes: 31 additions & 0 deletions src/stories/modifying-state.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Meta } from "@storybook/blocks";

<Meta title="Modifying State" />

<h1>Modifying State</h1>

<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>

<h4>Here is an example of how you can deselect a seat manually and retrieve the updated state:</h4>

```tsx
import { actions } from "@mezh-hq/react-seat-toolkit";

actions.deselectElement("<seat-id>");

const state = actions.getState();

console.log(state); // Updated workspace state of type STKData
```

<h4>Here is an example of how you can import and use the `store` to retrieve the current Redux state:</h4>

```tsx
import { store } from "@mezh-hq/react-seat-toolkit";

const state = store.getState();

console.log(state); // Current redux state (Not of type STKData)
```

<h4>For a full list of supported actions please have a look at its type definitions</h4>

0 comments on commit f0f7cc0

Please sign in to comment.