Skip to content

Commit

Permalink
Merge pull request #230 from Insire/ChangeTracking
Browse files Browse the repository at this point in the history
added change tracking for viewmodels
  • Loading branch information
Insire authored Jun 16, 2022
2 parents 316912d + 9a4653c commit 3a187a3
Show file tree
Hide file tree
Showing 99 changed files with 2,351 additions and 369 deletions.
34 changes: 30 additions & 4 deletions MvvmScarletToolkit.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28711.60
# Visual Studio Version 17
VisualStudioVersion = 17.1.32421.90
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvvmScarletToolkit", "src\MvvmScarletToolkit\MvvmScarletToolkit.csproj", "{D555C0FD-335D-4C64-B80B-8999E66402B8}"
EndProject
Expand All @@ -14,8 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.vsconfig = .vsconfig
appveyor.yml = appveyor.yml
build.cake = build.cake
Directory.Build.targets = Directory.Build.targets
MvvmScarletToolkit.props = MvvmScarletToolkit.props
src\Directory.Build.props = src\Directory.Build.props
src\Directory.Build.targets = src\Directory.Build.targets
MvvmScarletToolkit.ruleset = MvvmScarletToolkit.ruleset
README.md = README.md
EndProjectSection
Expand All @@ -42,6 +42,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvvmScarletToolkit.Xamarin.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvvmScarletToolkit.Wpf.Tests", "src\MvvmScarletToolkit.Wpf.Tests\MvvmScarletToolkit.Wpf.Tests.csproj", "{A9CE017F-B4C9-40DC-A092-DC5067956994}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvvmScarletToolkit.Observables.Tests", "src\MvvmScarletToolkit.Observables.Tests\MvvmScarletToolkit.Observables.Tests.csproj", "{F7EBB910-0AA9-4683-878B-06108492F2F8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -350,6 +352,30 @@ Global
{A9CE017F-B4C9-40DC-A092-DC5067956994}.Release|x64.Build.0 = Release|Any CPU
{A9CE017F-B4C9-40DC-A092-DC5067956994}.Release|x86.ActiveCfg = Release|Any CPU
{A9CE017F-B4C9-40DC-A092-DC5067956994}.Release|x86.Build.0 = Release|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|ARM.ActiveCfg = Debug|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|ARM.Build.0 = Debug|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|iPhone.Build.0 = Debug|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|x64.ActiveCfg = Debug|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|x64.Build.0 = Debug|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|x86.ActiveCfg = Debug|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|x86.Build.0 = Debug|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|Any CPU.Build.0 = Release|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|ARM.ActiveCfg = Release|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|ARM.Build.0 = Release|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|iPhone.ActiveCfg = Release|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|iPhone.Build.0 = Release|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|x64.ActiveCfg = Release|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|x64.Build.0 = Release|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|x86.ActiveCfg = Release|Any CPU
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MvvmScarletToolkit

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Insire/Maple/blob/master/license.md)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Insire/MvvmScarletToolkit/blob/master/license.md)
[![NuGet](https://img.shields.io/nuget/v/MvvmScarletToolkit.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/MvvmScarletToolkit/)
[![Build status](https://dev.azure.com/SoftThorn/MvvmScarletToolkit/_apis/build/status/MvvmScarletToolkit-CD)](https://dev.azure.com/SoftThorn/MvvmScarletToolkit/_build/latest?definitionId=1)
[![CodeFactor](https://www.codefactor.io/repository/github/insire/mvvmscarlettoolkit/badge)](https://www.codefactor.io/repository/github/insire/mvvmscarlettoolkit)
Expand All @@ -24,6 +24,8 @@ Pre release nuget packages are available [here](https://pkgs.dev.azure.com/SoftT
- INotifyPropertyChanged base classes for single instance viewmodels and collection viewmodels
- Localization ViewModels (switching language without app restart)
- Threadsafe busy state notifications via IBusyStack interface
- ChangeTracker based on INotifyPropertyChanged
- ChangeTracker based on PropertyChangedMessage\<T> (from CommunityToolkit.Mvvm)
- Helper viewmodels for
- paging
- enums
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

<PropertyGroup>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<LangVersion>9.0</LangVersion>
<LangVersion>10.0</LangVersion>
<CodeAnalysisRuleSet>..\..\MvvmScarletToolkit.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup Condition=" '$(Configuration)'=='Debug' ">
<PackageReference Include="Roslynator.Analyzers" Version="3.2.2">
<PackageReference Include="Roslynator.Analyzers" Version="4.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
83 changes: 83 additions & 0 deletions src/MvvmScarletToolkit.Abstractions/IChangeTracker.cs
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 src/MvvmScarletToolkit.Abstractions/IToolkitChangeTracker.cs
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.244">
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.107">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/MvvmScarletToolkit.Commands/IScarletCommandBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Toolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging;
using MvvmScarletToolkit.Commands;
using System;
using System.ComponentModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0-preview4" />

<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.244">
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.107">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DynamicData" Version="7.4.3" />
<PackageReference Include="DynamicData" Version="7.9.1" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>
Expand Down
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 src/MvvmScarletToolkit.Observables.Tests/BroadCastViewModel.cs
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)
{
}
}
}
9 changes: 9 additions & 0 deletions src/MvvmScarletToolkit.Observables.Tests/ITestViewModel.cs
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; }
}
}
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>
Loading

0 comments on commit 3a187a3

Please sign in to comment.