Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to handle Data while Undo/Redo actions? (Read 74 times)
Avinash
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 22
Joined: Nov 12th, 2024
How to handle Data while Undo/Redo actions?
Jan 29th, 2025 at 6:20am
Print Post  
I have create an simple diagram and on every node create or link create am saving data into a model, which looks like below example JSON. now when an user is doing undo/Redo actions how do i Add or remove data from my model, is there any method that stores Undo/redo data.

{"nodes":[{"id":0,"shape":"Container","text":"Test App","color":"#FFF8DC","children":[1,2,3,4,5,6]},{"id":1,"shape":"Delay","text":"A","color":"#66CDAA"},{"id":2,"shape":"Rectang
le","text":"B","color":"#FFB6A5"},{"id":3,"shape":"Arrow7","text":"C","color":"#
C8A2C8"},{"id":4,"shape":"DataTransmition","text":"D","color":"#FF91A4"},{"id":5
,"shape":"Actor","text":"E","color":"#B0E2FF"},{"id":6,"shape":"ExternalOrganiza
tion","text":"F","color":"#BA55D3"}],"links":[{"origin":1,"target":2},{"origin":1,"target":3},{"origin":1,"target":4},{"origin":1,"target":5},{"origin":1,"target":6}]}
  

image__5_.png ( 26 KB | 9 Downloads )
image__5_.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3343
Joined: Oct 19th, 2005
Re: How to handle Data while Undo/Redo actions?
Reply #1 - Jan 29th, 2025 at 7:20am
Print Post  
Instead of nodeCreated and linkCreated events, try handling the itemAdded one. Former are raised only when users draw interactively on the canvas, latter is also raised by undo / redo.

Regards,
Slavcho
Mindfusion
« Last Edit: Jan 29th, 2025 at 1:53pm by Slavcho »  
Back to top
 
IP Logged
 
Avinash
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 22
Joined: Nov 12th, 2024
Re: How to handle Data while Undo/Redo actions?
Reply #2 - Jan 30th, 2025 at 6:55am
Print Post  
I have events to itemAdded and itemRemoved for both but on undo the events are triggring but not in redo?

When i add nodes or links itemAdded is triggering but not only in Redo.



   case 'itemAdded':
        console.log("Item Added:", args);
        console.log("sender", sender);
        if (args.node) {
          console.log("Added Node:", args.node);
        }
        if (args.link) {
          console.log("Added Link:", args.link);
        }
        break;
      case 'itemRemoved':
        console.log("Item Removed:", args);
        console.log("sender", sender);
        if (args.node) {
          console.log("Deleted Node:", args.node);
        }
        if (args.link) {
          console.log("Deleted Link:", args.link);
        }
        break;
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3343
Joined: Oct 19th, 2005
Re: How to handle Data while Undo/Redo actions?
Reply #3 - Jan 30th, 2025 at 8:05am
Print Post  
These receive an ItemEventArgs.item value as argument, and not node / link ones you are checking in code above. If you need to apply type-dependent logic, use the instanceof operator to verify if item is DiagramNode or DiagramLink.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint