Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you just need to decompose your problem into smaller ones.</p> <p>First problem: Q: How to represent the steps in your app with the memento/command pattern? First off, I have no idea exactly how your app works but hopefully you will see where I am going with this. Say I want to place a ClassNode on the diagram that with the following properties </p> <pre><code>{ width:100, height:50, position:(10,25), content:"Am I certain?", edge-connections:null} </code></pre> <p>That would be wrapped up as a command object. Say that goes to a DiagramController. Then the diagram controller's responsibility can be to record that command (push onto a stack would be my bet) and pass the command to a DiagramBuilder for example. The DiagramBuilder would actually be responsible for updating the display.</p> <pre><code>DiagramController { public DiagramController(diagramBuilder:DiagramBuilder) { this._diagramBuilder = diagramBuilder; this._commandStack = new Stack(); } public void Add(node:ConditionalNode) { this._commandStack.push(node); this._diagramBuilder.Draw(node); } public void Undo() { var node = this._commandStack.pop(); this._diagramBuilderUndraw(node); } } </code></pre> <p>Some thing like that should do it and of course there will be plenty of details to sort out. By the way, the more properties your nodes have the more detailed Undraw is going to have to be.</p> <p>Using an id to link the command in your stack to the element drawn might be a good idea. That might look like this:</p> <pre><code>DiagramController { public DiagramController(diagramBuilder:DiagramBuilder) { this._diagramBuilder = diagramBuilder; this._commandStack = new Stack(); } public void Add(node:ConditionalNode) { string graphicalRefId = this._diagramBuilder.Draw(node); var nodePair = new KeyValuePair&lt;string, ConditionalNode&gt; (graphicalRefId, node); this._commandStack.push(nodePair); } public void Undo() { var nodePair = this._commandStack.pop(); this._diagramBuilderUndraw(nodePair.Key); } } </code></pre> <p>At this point you don't absolutely <em>have to have</em> the object since you have the ID but it will be helpful should you decide to also implement redo functionality. A good way to generate the id for your nodes would be to implement a hashcode method for them except for the fact that you wouldn't be guaranteed not to duplicate your nodes in such a way that would cause the hash code to be identical.</p> <p>The next part of the problem is within your DiagramBuilder because you're trying to figure out how the heck to deal with these commands. For that all I can say is to really just ensure you can create an inverse action for each type of component you can add. To handle the delinking you can look at the edge-connection property (links in your code I think) and notify each of the edge-connections that they are to disconnect from the specific node. I would assume that on disconnection they could redraw themselves appropriately.</p> <p>To kinda summarize, I would recommend not keeping a reference to your nodes in the stack but instead just a kind of token that represents a given node's state at that point. This will allow you to represent the same node in your undo stack at multiple places without it referring to the same object.</p> <p>Post if you've got Q's. This is a complex issue.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload