-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Browser and demo #3
Comments
Hi, thank you for your interest in T(a)rdis. I tried to make all the examples that is needed to fully understand how T(a)rdis works. The past/future/present term was (for me) the greater way to hilight how T(a)rdis works, but I can understand how it can be confusing. When your use the These objects are meant in the way that merging them with the source is how you apply the patch. Merging I hope I was clear, and will answer any of your further questions. |
Thank you. I understand at 99%, but make multiple changes, save diff in an
array and play with this array when I do multiple undo and redo is not
easy.
I make it without diff in a big array of full json, it's work (without your
script). I can do an undo and redo with t(a)rdis, but my json time machine
never works for me.
For now my cheap solution works, but I spend a lot of time to make it
better with your script. So a demo with history undo redo will be really
appreciate for novices and me.
My json looks like '{a:[0, 1],b:[0, 0]}'.
|
For this task, I urge to use the Given the following object : {
a: [0, 1],
b: [0, 0]
} if you perform the following change : {
a: [0, 1],
- b: [0, 0]
+ b: [1, 1]
} Using the const changes = diff(source, target, true) will give you the following {
do: {
a: { length: 2 },
b: {0: 1, 1: 1, length: 2}
},
undo: {
a: { length: 2 },
b: { 0: 0, 1: 0, length: 2 }
}
} (Array are changed to objects in the diff result to only keep track of changed items, and length for added/removed items) To apply the changes, I recommand you to use the Undo changes : const source = patch(target, changes.undo, true, true, true) Redo changes : const target = patch(source, changes.do, true, true, true) The API reference is here : https://github.com/Swizz/trdis#api |
The 3
|
I see two misstakes and one bug of mine (I will fix it within the day). First you need to use the diff this way : 37 function dataDiffUpdate(){
38 dataDiff = dataDiff.slice(0,historyPosition);
- 39 dataDiff.push(diff(data,_data,true,true,true));
+ 39 dataDiff.push(diff(_data,data,true));
40 _data = JSON.parse(JSON.stringify(data));
41 historyPosition = dataDiff.length;
42 console.log(historyPosition);
43
44 } (diff only have one option : deep) And this one, is more about how you use cursor to get the current change. 29 function undo(){
30 if(historyPosition>1){
31 historyPosition--;
- 32 data = ( patch(data,dataDiff[historyPosition-1].undo,true,true,true));
+ 32 data = ( patch(data,dataDiff[historyPosition].undo,true,true,true));
33 console.log(JSON.stringify(data));
34
35 }
36 } The bug I will fix is about how deep and array works. |
Oh yes, I remember on an other test the wrong switch between old and new :) |
The fix is now published under 1.0.1 |
I will try in few days, thank you ! |
Something go wrong :( |
it's look ok 👍 |
Finaly, it's not 100% ok from Here |
It's look like something great but how to use it on browser ?
I would like to make a undo/redo on an object, there is information but a real example (codepen or another) could be precious.
Not clear.
The text was updated successfully, but these errors were encountered: