-
Notifications
You must be signed in to change notification settings - Fork 3
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
Reset changes #64
Comments
Not sure what you mean, can you explain the use case and perhaps some pseudo code for the API? |
Suppose I'm tracking changes in UI viewmodels, and user wants to cancel changes. How hard would it be to implement using this project? I think that changetracker probably has all information to do that. |
Maybe you want something like: public class ViewModel
{
private readonly Dto snapshot;
public ViewModel(Dto dto)
{
this.snapshot = DeepCopy(dto);
this.Editable = dto;
this.DirtyTracker = Track.IsDirty(this.Editable, this.snapshot);
}
public Dto Editable { get; }
public IDirtyTracker DirtyTracker { get; }
public void Save()
{
// Save Editable
Copy.PropertyValues(this.Editable, this.snapshot);
}
public void Cancel()
{
Copy.PropertyValues(this.snapshot, this.Editable);
}
} Kept it short. If you don't need to preserve references things get even simpler: public class ViewModel
{
private Dto snapshot;
public ViewModel(Dto dto)
{
this.snapshot = DeepCopy(dto);
this.Editable = dto;
this.DirtyTracker = Track.IsDirty(this.Editable, this.snapshot);
}
public Dto Editable { get; }
public IDirtyTracker DirtyTracker { get; }
public void Save()
{
// Save Editable
this.DirtyTracker.Dispose();
this.snapshot = DeepCopy(this.Editable);
this.DirtyTracker = Track.IsDirty(this.Editable, this.snapshot);
}
public void Cancel()
{
this.DirtyTracker.Dispose();
this.Editable = DeepCopy(this.snapshot);
this.DirtyTracker = Track.IsDirty(this.Editable, this.snapshot);
}
} Syntax probably slightly off. |
Yes, that makes sense. Thank you for detailed response. I guess I'll have to rework my use of Dto objects to make them easily exchangeable. |
You can make a small prototype and see that it works first, been a while since I used this lib so a bit rusty on it. Also we should add a small sample to the docs. |
Did it work for you? |
No, I haven't. But you answered my questions. I guess this issue can be tagged and closed. |
I think machinery is in place to be able to reset or undo changes. What do you think?
The text was updated successfully, but these errors were encountered: