Skip to content

Commit

Permalink
Merge pull request #148 from jonnor/fix-metadata-on-undoing-remove
Browse files Browse the repository at this point in the history
Fix metadata on undoing remove
  • Loading branch information
bergie committed Feb 26, 2014
2 parents 4d17653 + 6f8b16d commit 0edc0c1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions spec/Journal.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ describe 'Journal', ->
Baz(Foo) Baz(Foo)
Foo out -> in Baz Foo out -> in Baz
'42' -> in Foo '42' -> in Foo
META Foo out -> in Baz
Foo out -X> in Baz Foo out -X> in Baz
'42' -X> in Foo '42' -X> in Foo
META Foo
DEL Foo(Bar) DEL Foo(Bar)
<<< 1: test1""" <<< 1: test1"""
chai.expect(j.toPrettyString(0,2)).to.equal ref chai.expect(j.toPrettyString(0,2)).to.equal ref
Expand Down
7 changes: 7 additions & 0 deletions src/lib/Graph.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class Graph extends EventEmitter


@checkTransactionStart() @checkTransactionStart()
port = @inports[publicPort] port = @inports[publicPort]
@setInportMetadata publicPort, {}
delete @inports[publicPort] delete @inports[publicPort]
@emit 'removeInport', publicPort, port @emit 'removeInport', publicPort, port
@checkTransactionEnd() @checkTransactionEnd()
Expand Down Expand Up @@ -194,6 +195,7 @@ class Graph extends EventEmitter
@checkTransactionStart() @checkTransactionStart()


port = @outports[publicPort] port = @outports[publicPort]
@setOutportMetadata publicPort, {}
delete @outports[publicPort] delete @outports[publicPort]
@emit 'removeOutport', publicPort, port @emit 'removeOutport', publicPort, port


Expand Down Expand Up @@ -242,6 +244,7 @@ class Graph extends EventEmitter
for group in @groups for group in @groups
continue unless group continue unless group
continue unless group.name is groupName continue unless group.name is groupName
@setGroupMetadata group.name, {}
@groups.splice @groups.indexOf(group), 1 @groups.splice @groups.indexOf(group), 1
@emit 'removeGroup', group @emit 'removeGroup', group


Expand Down Expand Up @@ -332,6 +335,8 @@ class Graph extends EventEmitter
continue if index is -1 continue if index is -1
group.nodes.splice index, 1 group.nodes.splice index, 1


@setNodeMetadata id, {}

if -1 isnt @nodes.indexOf node if -1 isnt @nodes.indexOf node
@nodes.splice @nodes.indexOf(node), 1 @nodes.splice @nodes.indexOf(node), 1


Expand Down Expand Up @@ -466,12 +471,14 @@ class Graph extends EventEmitter
if node2 and port2 if node2 and port2
unless edge.to.node is node2 and edge.to.port is port2 unless edge.to.node is node2 and edge.to.port is port2
continue continue
@setEdgeMetadata edge.from.node, edge.from.port, edge.to.node, edge.to.port, {}
@emit 'removeEdge', edge @emit 'removeEdge', edge
@edges.splice index, 1 @edges.splice index, 1
if edge.to.node is node and edge.to.port is port if edge.to.node is node and edge.to.port is port
if node2 and port2 if node2 and port2
unless edge.from.node is node2 and edge.from.port is port2 unless edge.from.node is node2 and edge.from.port is port2
continue continue
@setEdgeMetadata edge.from.node, edge.from.port, edge.to.node, edge.to.port, {}
@emit 'removeEdge', edge @emit 'removeEdge', edge
@edges.splice index, 1 @edges.splice index, 1


Expand Down
8 changes: 5 additions & 3 deletions src/lib/Journal.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ entryToPrettyString = (entry) ->
when 'addNode' then "#{a.id}(#{a.component})" when 'addNode' then "#{a.id}(#{a.component})"
when 'removeNode' then "DEL #{a.id}(#{a.component})" when 'removeNode' then "DEL #{a.id}(#{a.component})"
when 'renameNode' then "RENAME #{a.oldId} #{a.newId}" 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 '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 '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}" when 'changeEdge' then "META #{a.from.node} #{a.from.port} -> #{a.to.port} #{a.to.node}"
Expand Down Expand Up @@ -118,8 +118,8 @@ class Journal extends EventEmitter
@appendCommand 'addEdge', edge @appendCommand 'addEdge', edge
@graph.on 'removeEdge', (edge) => @graph.on 'removeEdge', (edge) =>
@appendCommand 'removeEdge', edge @appendCommand 'removeEdge', edge
@graph.on 'changeEdge', (edge) => @graph.on 'changeEdge', (edge, oldMeta) =>
@appendCommand 'removeEdge', edge @appendCommand 'changeEdge', {from: edge.from, to: edge.to, new: edge.metadata, old: oldMeta}
@graph.on 'addInitial', (iip) => @graph.on 'addInitial', (iip) =>
@appendCommand 'addInitial', iip @appendCommand 'addInitial', iip
@graph.on 'removeInitial', (iip) => @graph.on 'removeInitial', (iip) =>
Expand Down Expand Up @@ -197,6 +197,7 @@ class Journal extends EventEmitter
when 'changeNode' then @graph.setNodeMetadata a.id, calculateMeta(a.old, a.new) when 'changeNode' then @graph.setNodeMetadata a.id, calculateMeta(a.old, a.new)
when 'addEdge' then @graph.addEdge a.from.node, a.from.port, a.to.node, a.to.port when 'addEdge' then @graph.addEdge a.from.node, a.from.port, a.to.node, a.to.port
when 'removeEdge' then @graph.removeEdge a.from.node, a.from.port, a.to.node, a.to.port when 'removeEdge' then @graph.removeEdge a.from.node, a.from.port, a.to.node, a.to.port
when 'changeEdge' then @graph.setEdgeMetadata a.from.node, a.from.port, a.to.node, a.to.port, calculateMeta(a.old, a.new)
when 'addInitial' then @graph.addInitial a.from.data, a.to.node, a.to.port when 'addInitial' then @graph.addInitial a.from.data, a.to.node, a.to.port
when 'removeInitial' then @graph.removeInitial a.to.node, a.to.port when 'removeInitial' then @graph.removeInitial a.to.node, a.to.port
when 'startTransaction' then null when 'startTransaction' then null
Expand Down Expand Up @@ -224,6 +225,7 @@ class Journal extends EventEmitter
when 'changeNode' then @graph.setNodeMetadata a.id, calculateMeta(a.new, a.old) when 'changeNode' then @graph.setNodeMetadata a.id, calculateMeta(a.new, a.old)
when 'addEdge' then @graph.removeEdge a.from.node, a.from.port, a.to.node, a.to.port when 'addEdge' then @graph.removeEdge a.from.node, a.from.port, a.to.node, a.to.port
when 'removeEdge' then @graph.addEdge a.from.node, a.from.port, a.to.node, a.to.port when 'removeEdge' then @graph.addEdge a.from.node, a.from.port, a.to.node, a.to.port
when 'changeEdge' then @graph.setEdgeMetadata a.from.node, a.from.port, a.to.node, a.to.port, calculateMeta(a.new, a.old)
when 'addInitial' then @graph.removeInitial a.to.node, a.to.port when 'addInitial' then @graph.removeInitial a.to.node, a.to.port
when 'removeInitial' then @graph.addInitial a.from.data, a.to.node, a.to.port when 'removeInitial' then @graph.addInitial a.from.data, a.to.node, a.to.port
when 'startTransaction' then null when 'startTransaction' then null
Expand Down

0 comments on commit 0edc0c1

Please sign in to comment.