Skip to content

Commit 196a98b

Browse files
committed
add disable garbage collector
fixes #3
1 parent 53ff341 commit 196a98b

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/MemoryView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ export const MemoryView = () => {
426426
className="memory"
427427
nodes={nodes.map((n) => {
428428
n.className = "";
429-
n.deletable = false;
429+
n.deletable = memory.options.disableGarbageCollector;
430430
if (
431431
previousMethodCall !== undefined &&
432432
isConnectedTo(n.id, previousMethodCall.id, nodes, edges)
@@ -498,13 +498,13 @@ export const MemoryView = () => {
498498
<button onClick={onEdit}>Edit</button>
499499
</div>
500500
</Panel>
501-
<Panel position="bottom-right">
501+
{!memory.options.disableGarbageCollector && <Panel position="bottom-right">
502502
<div className="button-group">
503503
<button className="button-gc" onClick={onGC}>
504504
Run Garbage Collector
505505
</button>
506506
</div>
507-
</Panel>
507+
</Panel>}
508508
<Controls />
509509
<Background />
510510
</ReactFlow>

src/ObjectNode.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
import { Attribute, Obj, numericDataTypes, primitveDataTypes } from "./memory";
1212
import { isConnectedToMethodCall, isConnectedToVariable } from "./utils";
1313
import { CustomEdgeType, CustomNodeType } from "./types";
14+
import useStore, { RFState } from "./store";
15+
import { shallow } from "zustand/shallow";
1416

1517
function AttributeHandle({
1618
name,
@@ -108,10 +110,15 @@ export function isObjectNode(node: CustomNodeType): node is ObjectNodeType {
108110
return node.type === "object";
109111
}
110112

113+
const selector = (state: RFState) => ({
114+
...state.memory.options,
115+
});
116+
111117
function ObjectNode({ id, data }: NodeProps<ObjectNodeType>) {
118+
const { disableGarbageCollector } = useStore(selector, shallow);
112119
const nodes = useNodes();
113120
const edges = useEdges();
114-
const gc =
121+
const gc = !disableGarbageCollector &&
115122
!isConnectedToVariable(id, nodes, edges) &&
116123
!isConnectedToMethodCall(id, nodes, edges);
117124

src/memory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export type Memory = {
9292
zoom: number;
9393
};
9494
options: {
95+
disableGarbageCollector?: boolean;
9596
hideSidebar?: boolean;
9697
hideCallMethod?: boolean;
9798
hideDeclareGlobalVariable?: boolean;

0 commit comments

Comments
 (0)