Skip to content

Commit

Permalink
clean up stack stub code from state
Browse files Browse the repository at this point in the history
  • Loading branch information
david zhou authored and david zhou committed Mar 10, 2024
1 parent 51d020b commit b0b7bdb
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,15 @@
* TODO: this is incomplete, horrible code
* Need huge refactor work
*/
import React from 'react';
import styles from './StackInspector.module.scss';
import { useGlobalStore } from '../../Store/globalStateStore';

const StackInspector = () => {
const { stackInspector: debuggerData }: { stackInspector: any } = useGlobalStore().visualizer;
return (
<div className={styles.stackInspector}>
<div style={{ fontSize: 'small' }}>
Note: This is so far just a placeholder, doesn&#39;t show actual stack data from the
debugger yet.
</div>
{debuggerData.stack.map((stackFrame, idx) => (
<div className={styles.frame} key={idx}>
<div className={styles.frameHeader}>
<code className={styles.function}>{stackFrame.callerLocation.function}()</code>{' '}
<span className={styles.location}>
@ {stackFrame.callerLocation.file}:{stackFrame.callerLocation.line}:
{stackFrame.callerLocation.column}
</span>
</div>
<dl>
{stackFrame.locals.map((stackLocal) => (
<>
<dt>
<code className={styles.type}>{stackLocal.type}</code>
<code className={styles.name}>{stackLocal.name}</code>
</dt>
<dd>
<code className={styles.value}>{stackLocal.value}</code>
</dd>
</>
))}
</dl>
</div>
))}
</div>
);
};
Expand Down
3 changes: 0 additions & 3 deletions client/src/visualiser-debugger/Store/globalStateStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { visualizerFactory } from '../Component/Visualizer/Visulizer/visualizerF
import { UserAnnotation } from '../Types/annotationType';
import { BackendState, BackendTypeDeclaration, INITIAL_BACKEND_STATE } from '../Types/backendType';
import { VisualizerType } from '../Types/visualizerType';
import * as InspectorDummy from './stackInpsectorDummyData.json';

export type UiState = {
width: number;
Expand All @@ -19,7 +18,6 @@ export type VisualizerParam = {
visComponent: VisualizerComponent;
parser: Parser;
typeDeclarations: BackendTypeDeclaration[];
stackInspector: any;
};

export type GlobalStateStore = {
Expand All @@ -43,7 +41,6 @@ export const DEFAULT_GLOBAL_STORE: GlobalStateStore = {
visComponent: visualizerFactory(VisualizerType.LINKED_LIST),
parser: parserFactory(VisualizerType.LINKED_LIST),
typeDeclarations: [],
stackInspector: InspectorDummy,
},
currFrame: INITIAL_BACKEND_STATE,
};
Expand Down
72 changes: 0 additions & 72 deletions client/src/visualiser-debugger/Store/stackInpsectorDummyData.json

This file was deleted.

19 changes: 4 additions & 15 deletions client/src/visualiser-debugger/Store/visualizerStateStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { UseBoundStore, StoreApi, create } from 'zustand';
import { VisualizerComponent } from '../Component/Visualizer/Visulizer/visualizer';
import { GenericGraph, INITIAL_GRAPH } from '../Types/frontendType';
import { GlobalStateStore } from './globalStateStore';

type State = {
states: GenericGraph[];
Expand All @@ -10,8 +8,8 @@ type State = {
};
type Action = {
newState: (newState: GenericGraph) => void;
nextState: () => void;
lastState: () => void;
setNextState: () => void;
setLastState: () => void;
};

export const useFrontendStateStore: UseBoundStore<StoreApi<State & Action>> = create<
Expand All @@ -31,7 +29,7 @@ export const useFrontendStateStore: UseBoundStore<StoreApi<State & Action>> = cr
currStateIdx: state.currStateIdx + 1,
}));
},
nextState: () => {
setNextState: () => {
if (
useFrontendStateStore.getState().currStateIdx >=
useFrontendStateStore.getState().states.length - 1
Expand All @@ -42,7 +40,7 @@ export const useFrontendStateStore: UseBoundStore<StoreApi<State & Action>> = cr
currStateIdx: state.currStateIdx + 1,
}));
},
lastState: () => {
setLastState: () => {
if (useFrontendStateStore.getState().currStateIdx <= 0) {
return;
}
Expand All @@ -51,12 +49,3 @@ export const useFrontendStateStore: UseBoundStore<StoreApi<State & Action>> = cr
}));
},
}));

export interface StateManagerProp {
state: GenericGraph;
settings: GlobalStateStore;
setSettings: React.Dispatch<React.SetStateAction<GlobalStateStore>>;
nextState: () => void;

Visualizer: VisualizerComponent;
}

0 comments on commit b0b7bdb

Please sign in to comment.