Skip to content
Browse files

Graph: Emit metadata changes on node/edge/ports removal

Needed for the journal to be able to restore metadata when undoing removals.
Fixes noflo/noflo-ui#96, undoing node removal resets position to 0,0
  • Loading branch information...
1 parent c6a2b59 commit 6f8b16d0c0ce87e961264c10bd906abe12727e58 @jonnor jonnor committed Feb 26, 2014
Showing with 10 additions and 1 deletion.
  1. +2 −0 spec/Journal.coffee
  2. +7 −0 src/lib/Graph.coffee
  3. +1 −1 src/lib/Journal.coffee
View
2 spec/Journal.coffee
@@ -51,8 +51,10 @@ describe 'Journal', ->
Baz(Foo)
Foo out -> in Baz
'42' -> in Foo
+ META Foo out -> in Baz
Foo out -X> in Baz
'42' -X> in Foo
+ META Foo
DEL Foo(Bar)
<<< 1: test1"""
chai.expect(j.toPrettyString(0,2)).to.equal ref
View
7 src/lib/Graph.coffee
@@ -146,6 +146,7 @@ class Graph extends EventEmitter
@checkTransactionStart()
port = @inports[publicPort]
+ @setInportMetadata publicPort, {}
delete @inports[publicPort]
@emit 'removeInport', publicPort, port
@checkTransactionEnd()
@@ -194,6 +195,7 @@ class Graph extends EventEmitter
@checkTransactionStart()
port = @outports[publicPort]
+ @setOutportMetadata publicPort, {}
delete @outports[publicPort]
@emit 'removeOutport', publicPort, port
@@ -242,6 +244,7 @@ class Graph extends EventEmitter
for group in @groups
continue unless group
continue unless group.name is groupName
+ @setGroupMetadata group.name, {}
@groups.splice @groups.indexOf(group), 1
@emit 'removeGroup', group
@@ -332,6 +335,8 @@ class Graph extends EventEmitter
continue if index is -1
group.nodes.splice index, 1
+ @setNodeMetadata id, {}
+
if -1 isnt @nodes.indexOf node
@nodes.splice @nodes.indexOf(node), 1
@@ -466,12 +471,14 @@ class Graph extends EventEmitter
if node2 and port2
unless edge.to.node is node2 and edge.to.port is port2
continue
+ @setEdgeMetadata edge.from.node, edge.from.port, edge.to.node, edge.to.port, {}
@emit 'removeEdge', edge
@edges.splice index, 1
if edge.to.node is node and edge.to.port is port
if node2 and port2
unless edge.from.node is node2 and edge.from.port is port2
continue
+ @setEdgeMetadata edge.from.node, edge.from.port, edge.to.node, edge.to.port, {}
@emit 'removeEdge', edge
@edges.splice index, 1
View
2 src/lib/Journal.coffee
@@ -20,7 +20,7 @@ entryToPrettyString = (entry) ->
when 'addNode' then "#{a.id}(#{a.component})"
when 'removeNode' then "DEL #{a.id}(#{a.component})"
when 'renameNode' then "RENAME #{a.oldId} #{a.newId}"
- when 'changeNode' then "META #{a.id}(#{a.component})"
+ when 'changeNode' then "META #{a.id}"
when 'addEdge' then "#{a.from.node} #{a.from.port} -> #{a.to.port} #{a.to.node}"
when 'removeEdge' then "#{a.from.node} #{a.from.port} -X> #{a.to.port} #{a.to.node}"
when 'changeEdge' then "META #{a.from.node} #{a.from.port} -> #{a.to.port} #{a.to.node}"

0 comments on commit 6f8b16d

Please sign in to comment.
Something went wrong with that request. Please try again.