-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from Insire/ChangeTracking
added change tracking for viewmodels
- Loading branch information
Showing
99 changed files
with
2,351 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.ComponentModel; | ||
|
||
namespace MvvmScarletToolkit | ||
{ | ||
public interface IChangeTracker : IDisposable | ||
{ | ||
/// <summary> | ||
/// Check if any tracked isntances were changed | ||
/// </summary> | ||
bool HasChanges(); | ||
|
||
/// <summary> | ||
/// Check if the provided <paramref name="instance"/> is being tracked and was changed | ||
/// </summary> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
bool HasChanges<T>(T instance) | ||
where T : class, INotifyPropertyChanged; | ||
|
||
/// <summary> | ||
/// Count how many properties of the provided <paramref name="instance"/> were changed | ||
/// </summary> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
int CountChanges<T>(T instance) | ||
where T : class, INotifyPropertyChanged; | ||
|
||
/// <summary> | ||
/// Track whether <paramref name="instance"/> raised <see cref="INotifyPropertyChanged.PropertyChanged"/> | ||
/// </summary> | ||
/// <param name="instance">The instance to track</param> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
void Track<T>(T instance) | ||
where T : class, INotifyPropertyChanged; | ||
|
||
/// <summary> | ||
/// Stops tracking all instances | ||
/// </summary> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
void StopAllTracking(); | ||
|
||
/// <summary> | ||
/// Stops tracking <paramref name="instance"/> | ||
/// </summary> | ||
/// <param name="instance"></param> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
void StopTracking<T>(T instance) | ||
where T : class, INotifyPropertyChanged; | ||
|
||
/// <summary> | ||
/// Discards any tracked changes | ||
/// </summary> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
void ClearAllChanges(); | ||
|
||
/// <summary> | ||
/// Discards any tracked changes for <paramref name="instance"/> | ||
/// </summary> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
void ClearChanges<T>(T instance) | ||
where T : class, INotifyPropertyChanged; | ||
|
||
/// <summary> | ||
/// Discards any new change notification, while the returned subscription is active | ||
/// </summary> | ||
/// <returns>the subscription</returns> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
IDisposable SuppressAllChanges(); | ||
|
||
/// <summary> | ||
/// Discards any new change notification for <paramref name="instance"/>, while the returned subscription is active | ||
/// </summary> | ||
/// <returns>the subscription</returns> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
IDisposable SuppressChanges<T>(T instance) | ||
where T : class, INotifyPropertyChanged; | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
src/MvvmScarletToolkit.Abstractions/IToolkitChangeTracker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.ComponentModel; | ||
|
||
namespace MvvmScarletToolkit | ||
{ | ||
public interface IToolkitChangeTracker : IDisposable | ||
{ | ||
/// <summary> | ||
/// Check if any tracked isntances were changed | ||
/// </summary> | ||
bool HasChanges(); | ||
|
||
/// <summary> | ||
/// Check if the provided <paramref name="instance"/> is being tracked and was changed | ||
/// </summary> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
bool HasChanges<T>(T instance) | ||
where T : class, INotifyPropertyChanged; | ||
|
||
/// <summary> | ||
/// Count how many properties of the provided <paramref name="instance"/> were changed | ||
/// </summary> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
int CountChanges<T>(T instance) | ||
where T : class, INotifyPropertyChanged; | ||
|
||
/// <summary> | ||
/// Track whether <paramref name="instance"/> raised <see cref="INotifyPropertyChanged.PropertyChanged"/> | ||
/// </summary> | ||
/// <param name="instance">The instance to track</param> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
void Track<T, TPropertyType>(T instance) | ||
where T : class, INotifyPropertyChanged; | ||
|
||
/// <summary> | ||
/// Stops tracking all instances | ||
/// </summary> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
void StopAllTracking(); | ||
|
||
/// <summary> | ||
/// Stops tracking <paramref name="instance"/> | ||
/// </summary> | ||
/// <param name="instance"></param> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
void StopTracking<T>(T instance) | ||
where T : class, INotifyPropertyChanged; | ||
|
||
/// <summary> | ||
/// Discards any tracked changes | ||
/// </summary> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
void ClearAllChanges(); | ||
|
||
/// <summary> | ||
/// Discards any tracked changes for <paramref name="instance"/> | ||
/// </summary> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
void ClearChanges<T>(T instance) | ||
where T : class, INotifyPropertyChanged; | ||
|
||
/// <summary> | ||
/// Discards any new change notification, while the returned subscription is active | ||
/// </summary> | ||
/// <returns>the subscription</returns> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
IDisposable SuppressAllChanges(); | ||
|
||
/// <summary> | ||
/// Discards any new change notification for <paramref name="instance"/>, while the returned subscription is active | ||
/// </summary> | ||
/// <returns>the subscription</returns> | ||
/// <exception cref="ObjectDisposedException"></exception> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
IDisposable SuppressChanges<T>(T instance) | ||
where T : class, INotifyPropertyChanged; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/MvvmScarletToolkit.Observables.Tests/AttributedBroadCastViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
|
||
namespace MvvmScarletToolkit.Observables.Tests | ||
{ | ||
[ObservableRecipient] | ||
internal sealed partial class AttributedBroadCastViewModel : ObservableObject, ITestViewModel | ||
{ | ||
[ObservableProperty] | ||
[NotifyPropertyChangedRecipients] | ||
private string _property; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/MvvmScarletToolkit.Observables.Tests/BroadCastViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Messaging; | ||
|
||
namespace MvvmScarletToolkit.Observables.Tests | ||
{ | ||
internal sealed partial class BroadCastViewModel : ObservableRecipient, ITestViewModel | ||
{ | ||
private string property; | ||
public string Property | ||
{ | ||
get { return property; } | ||
set { SetProperty(ref property, value, true); } | ||
} | ||
|
||
public BroadCastViewModel(IMessenger messenger) | ||
: base(messenger) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.ComponentModel; | ||
|
||
namespace MvvmScarletToolkit.Observables.Tests | ||
{ | ||
public interface ITestViewModel : INotifyPropertyChanged | ||
{ | ||
string Property { get; set; } | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/MvvmScarletToolkit.Observables.Tests/MvvmScarletToolkit.Observables.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp3.1;net5.0-windows;net6.0-windows</TargetFrameworks> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Moq" Version="4.18.1" /> | ||
<PackageReference Include="NSubstitute" Version="4.3.0" /> | ||
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.15" /> | ||
|
||
<PackageReference Include="nunit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\MvvmScarletToolkit.Abstractions\MvvmScarletToolkit.Abstractions.csproj" /> | ||
<ProjectReference Include="..\MvvmScarletToolkit.Commands\MvvmScarletToolkit.Commands.csproj" /> | ||
<ProjectReference Include="..\MvvmScarletToolkit.Observables\MvvmScarletToolkit.Observables.csproj" /> | ||
</ItemGroup> | ||
</Project> |
Oops, something went wrong.