Skip to content

fix node deletion #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/pages/edit/Editor/store/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ function createEditorStore(componentId: CCComponentId, store: CCStore) {
timeStep <= editorState.timeStep;
timeStep += 1
) {
console.log(timeStep);
const previousFrame = simulationCachedFrames[timeStep - 1] ?? null;
const inputValues = new Map();
const pins = store.componentPins.getManyByComponentId(componentId);
Expand Down
14 changes: 12 additions & 2 deletions src/store/componentPin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,24 @@ export class CCComponentPinStore extends EventEmitter<CCComponentPinStoreEvents>
if (toComponentPin) this.unregister(toComponentPin.id);
});
this.#store.connections.on("willUnregister", (connection) => {
this.register(this.createForNodePin(connection.to));
if (
!this.#store.nodePins.isMarkedAsDeleted(connection.to) &&
this.#store.nodePins.get(connection.to)
) {
this.register(this.createForNodePin(connection.to));
}
// output pins can have multiple connections
// so we need to check if the connection is the last one
if (
this.#store.connections.getConnectionsByNodePinId(connection.from)
.length === 1
) {
this.register(this.createForNodePin(connection.from));
if (
!this.#store.nodePins.isMarkedAsDeleted(connection.from) &&
this.#store.nodePins.get(connection.from)
) {
this.register(this.createForNodePin(connection.from));
}
}
});
}
Expand Down
8 changes: 8 additions & 0 deletions src/store/nodePin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class CCNodePinStore extends EventEmitter<CCNodePinStoreEvents> {

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

#markedAsDeleted: Set<CCNodePinId> = new Set();

/**
* Constructor of CCNodePinStore
* @param store store
Expand Down Expand Up @@ -100,11 +102,13 @@ export class CCNodePinStore extends EventEmitter<CCNodePinStoreEvents> {
*/
async unregister(id: CCNodePinId): Promise<void> {
const nodePin = nullthrows(this.#nodePins.get(id));
this.#markedAsDeleted.add(id);
await this.#store.transactionManager.runInTransaction(() => {
this.emit("willUnregister", nodePin);
this.#nodePins.delete(nodePin.id);
});
this.emit("didUnregister", nodePin);
this.#markedAsDeleted.delete(id);
}

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

isMarkedAsDeleted(id: CCNodePinId) {
return this.#markedAsDeleted.has(id);
}

/**
* Create a new pin
* @param partialPin pin without `id`
Expand Down
Loading