Skip to content

Commit

Permalink
ambr remove delete
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Aug 15, 2023
1 parent 9e3a8bd commit e96a633
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

`createNode` take `net` and create `nodePorts`

rename `node/createNode` to `net/addNode`

use `findNodePortsOrFail` instead of `findNodePortsOrCreate`

`Node` should not `input` and `output` ports
Expand Down
4 changes: 2 additions & 2 deletions src/lang/connect/disconnect.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Edge } from "../edge"
import { Net } from "../net"
import { deleteEdge } from "../net/deleteEdge"
import { deletePortConnection } from "../net/deletePortConnection"
import { removeEdge } from "../net/removeEdge"

export function disconnect(net: Net, edge: Edge): void {
removeEdge(net, edge)
deleteEdge(net, edge)

// Be careful about memory leak.
deletePortConnection(net, edge.first)
Expand Down
6 changes: 3 additions & 3 deletions src/lang/interact/interact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Checking } from "../checking"
import { compose } from "../compose/compose"
import { ActiveEdge } from "../edge"
import { Env } from "../env"
import { deleteEdgesOfNode } from "../net/deleteEdgesOfNode"
import { deleteNodePorts } from "../net/deleteNodePorts"
import { removeEdgesOfNode } from "../net/removeEdgesOfNode"

export type InteractOptions = {
checking?: Checking
Expand All @@ -14,8 +14,8 @@ export function interact(
activeEdge: ActiveEdge,
options: InteractOptions,
): void {
removeEdgesOfNode(env.net, activeEdge.first.node)
removeEdgesOfNode(env.net, activeEdge.second.node)
deleteEdgesOfNode(env.net, activeEdge.first.node)
deleteEdgesOfNode(env.net, activeEdge.second.node)

for (const word of activeEdge.rule.words) {
compose(activeEdge.rule.mod, env, word, {
Expand Down
2 changes: 1 addition & 1 deletion src/lang/net/removeEdge.ts → src/lang/net/deleteEdge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Edge } from "../edge"
import { Net } from "../net"

export function removeEdge(net: Net, edge: Edge): void {
export function deleteEdge(net: Net, edge: Edge): void {
const index = net.edges.indexOf(edge)
if (index !== -1) {
net.edges.splice(index, 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Net } from "../net"
import { Node } from "../node"
import { deleteEdge } from "./deleteEdge"
import { findPortConnection } from "./findPortConnection"
import { removeEdge } from "./removeEdge"

export function removeEdgesOfNode(net: Net, node: Node): void {
export function deleteEdgesOfNode(net: Net, node: Node): void {
for (const port of node.input) {
const connection = findPortConnection(net, port)
connection && removeEdge(net, connection.edge)
connection && deleteEdge(net, connection.edge)
}

for (const port of node.output) {
const connection = findPortConnection(net, port)
connection && removeEdge(net, connection.edge)
connection && deleteEdge(net, connection.edge)
}
}

0 comments on commit e96a633

Please sign in to comment.