|
1 | 1 | import isDeepEqual from "fast-deep-equal" |
2 | 2 | import { temporal } from "zundo" |
3 | 3 | import { create } from "zustand" |
4 | | -import { createJSONStorage, devtools, persist } from "zustand/middleware" |
| 4 | +import { createJSONStorage, persist } from "zustand/middleware" |
5 | 5 | import debounce from "../../utils/debounce" |
6 | 6 |
|
7 | 7 | import { AppStore } from "./api" |
8 | 8 |
|
9 | 9 | export const EXPORTED_FLOW_VERSION = "1.0" |
10 | 10 |
|
11 | 11 | // If app becomes too slow, might need to switch to async persistent storage. |
12 | | -// TODO: Remove devtools |
13 | 12 | export const useAppStore = create<AppStore>()( |
14 | | - devtools( |
15 | | - persist( |
16 | | - temporal( |
17 | | - (_) => ({ |
18 | | - nodes: [], |
19 | | - edges: [], |
20 | | - eipConfigs: {}, |
21 | | - selectedChildNode: null, |
22 | | - layout: { |
23 | | - orientation: "horizontal", |
24 | | - density: "comfortable", |
25 | | - }, |
26 | | - }), |
27 | | - { |
28 | | - limit: 50, |
29 | | - partialize: (state) => { |
30 | | - const newNodes = state.nodes.map((node) => { |
31 | | - const n = { ...node } |
32 | | - const { |
33 | | - selected, |
34 | | - draggable, |
35 | | - dragging, |
36 | | - positionAbsolute, |
37 | | - ...rest |
38 | | - } = n |
39 | | - return rest |
40 | | - }) |
| 13 | + persist( |
| 14 | + temporal( |
| 15 | + (_) => ({ |
| 16 | + nodes: [], |
| 17 | + edges: [], |
| 18 | + eipConfigs: {}, |
| 19 | + selectedChildNode: null, |
| 20 | + layout: { |
| 21 | + orientation: "horizontal", |
| 22 | + density: "comfortable", |
| 23 | + }, |
| 24 | + }), |
| 25 | + { |
| 26 | + limit: 50, |
| 27 | + partialize: (state) => { |
| 28 | + const newNodes = state.nodes.map((node) => { |
| 29 | + const n = { ...node } |
| 30 | + const { selected, draggable, dragging, positionAbsolute, ...rest } = |
| 31 | + n |
| 32 | + return rest |
| 33 | + }) |
41 | 34 |
|
42 | | - const { eipConfigs, edges, layout } = state |
43 | | - return { eipConfigs, edges, layout, nodes: newNodes } |
44 | | - }, |
| 35 | + const { eipConfigs, edges, layout } = state |
| 36 | + return { eipConfigs, edges, layout, nodes: newNodes } |
| 37 | + }, |
45 | 38 |
|
46 | | - equality: (pastState, currentState) => |
47 | | - isDeepEqual(pastState, currentState), |
| 39 | + equality: (pastState, currentState) => |
| 40 | + isDeepEqual(pastState, currentState), |
48 | 41 |
|
49 | | - handleSet: (handleSet) => |
50 | | - debounce<typeof handleSet>((state) => handleSet(state), 1000, true), |
51 | | - } |
52 | | - ), |
53 | | - { |
54 | | - name: "eipFlow", |
55 | | - version: Number(EXPORTED_FLOW_VERSION.split(".")[0]), |
56 | | - storage: createJSONStorage(() => localStorage), |
| 42 | + handleSet: (handleSet) => |
| 43 | + debounce<typeof handleSet>((state) => handleSet(state), 1000, true), |
57 | 44 | } |
58 | | - ) |
| 45 | + ), |
| 46 | + { |
| 47 | + name: "eipFlow", |
| 48 | + version: Number(EXPORTED_FLOW_VERSION.split(".")[0]), |
| 49 | + storage: createJSONStorage(() => localStorage), |
| 50 | + } |
59 | 51 | ) |
60 | 52 | ) |
0 commit comments