Skip to content

Commit 021c8bb

Browse files
authored
Merge pull request #49 from ut-code/fix-node-deletion
fix node deletion
2 parents bcae77e + 4e07240 commit 021c8bb

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/pages/edit/Editor/store/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ function createEditorStore(componentId: CCComponentId, store: CCStore) {
177177
timeStep <= editorState.timeStep;
178178
timeStep += 1
179179
) {
180-
console.log(timeStep);
181180
const previousFrame = simulationCachedFrames[timeStep - 1] ?? null;
182181
const inputValues = new Map();
183182
const pins = store.componentPins.getManyByComponentId(componentId);

src/store/componentPin.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,24 @@ export class CCComponentPinStore extends EventEmitter<CCComponentPinStoreEvents>
8989
if (toComponentPin) this.unregister(toComponentPin.id);
9090
});
9191
this.#store.connections.on("willUnregister", (connection) => {
92-
this.register(this.createForNodePin(connection.to));
92+
if (
93+
!this.#store.nodePins.isMarkedAsDeleted(connection.to) &&
94+
this.#store.nodePins.get(connection.to)
95+
) {
96+
this.register(this.createForNodePin(connection.to));
97+
}
9398
// output pins can have multiple connections
9499
// so we need to check if the connection is the last one
95100
if (
96101
this.#store.connections.getConnectionsByNodePinId(connection.from)
97102
.length === 1
98103
) {
99-
this.register(this.createForNodePin(connection.from));
104+
if (
105+
!this.#store.nodePins.isMarkedAsDeleted(connection.from) &&
106+
this.#store.nodePins.get(connection.from)
107+
) {
108+
this.register(this.createForNodePin(connection.from));
109+
}
100110
}
101111
});
102112
}

src/store/nodePin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export class CCNodePinStore extends EventEmitter<CCNodePinStoreEvents> {
2525

2626
#nodePins: Map<CCNodePinId, CCNodePin> = new Map();
2727

28+
#markedAsDeleted: Set<CCNodePinId> = new Set();
29+
2830
/**
2931
* Constructor of CCNodePinStore
3032
* @param store store
@@ -100,11 +102,13 @@ export class CCNodePinStore extends EventEmitter<CCNodePinStoreEvents> {
100102
*/
101103
async unregister(id: CCNodePinId): Promise<void> {
102104
const nodePin = nullthrows(this.#nodePins.get(id));
105+
this.#markedAsDeleted.add(id);
103106
await this.#store.transactionManager.runInTransaction(() => {
104107
this.emit("willUnregister", nodePin);
105108
this.#nodePins.delete(nodePin.id);
106109
});
107110
this.emit("didUnregister", nodePin);
111+
this.#markedAsDeleted.delete(id);
108112
}
109113

110114
/**
@@ -195,6 +199,10 @@ export class CCNodePinStore extends EventEmitter<CCNodePinStoreEvents> {
195199
return traverseNodePinMultiplexability(nodePinId, new Set());
196200
}
197201

202+
isMarkedAsDeleted(id: CCNodePinId) {
203+
return this.#markedAsDeleted.has(id);
204+
}
205+
198206
/**
199207
* Create a new pin
200208
* @param partialPin pin without `id`

0 commit comments

Comments
 (0)