Skip to content

Commit 3a187a3

Browse files
authored
Merge pull request #230 from Insire/ChangeTracking
added change tracking for viewmodels
2 parents 316912d + 9a4653c commit 3a187a3

File tree

99 files changed

+2351
-369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+2351
-369
lines changed

MvvmScarletToolkit.sln

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.28711.60
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.1.32421.90
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvvmScarletToolkit", "src\MvvmScarletToolkit\MvvmScarletToolkit.csproj", "{D555C0FD-335D-4C64-B80B-8999E66402B8}"
77
EndProject
@@ -14,8 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
.vsconfig = .vsconfig
1515
appveyor.yml = appveyor.yml
1616
build.cake = build.cake
17-
Directory.Build.targets = Directory.Build.targets
18-
MvvmScarletToolkit.props = MvvmScarletToolkit.props
17+
src\Directory.Build.props = src\Directory.Build.props
18+
src\Directory.Build.targets = src\Directory.Build.targets
1919
MvvmScarletToolkit.ruleset = MvvmScarletToolkit.ruleset
2020
README.md = README.md
2121
EndProjectSection
@@ -42,6 +42,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvvmScarletToolkit.Xamarin.
4242
EndProject
4343
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvvmScarletToolkit.Wpf.Tests", "src\MvvmScarletToolkit.Wpf.Tests\MvvmScarletToolkit.Wpf.Tests.csproj", "{A9CE017F-B4C9-40DC-A092-DC5067956994}"
4444
EndProject
45+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvvmScarletToolkit.Observables.Tests", "src\MvvmScarletToolkit.Observables.Tests\MvvmScarletToolkit.Observables.Tests.csproj", "{F7EBB910-0AA9-4683-878B-06108492F2F8}"
46+
EndProject
4547
Global
4648
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4749
Debug|Any CPU = Debug|Any CPU
@@ -350,6 +352,30 @@ Global
350352
{A9CE017F-B4C9-40DC-A092-DC5067956994}.Release|x64.Build.0 = Release|Any CPU
351353
{A9CE017F-B4C9-40DC-A092-DC5067956994}.Release|x86.ActiveCfg = Release|Any CPU
352354
{A9CE017F-B4C9-40DC-A092-DC5067956994}.Release|x86.Build.0 = Release|Any CPU
355+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
356+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
357+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|ARM.ActiveCfg = Debug|Any CPU
358+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|ARM.Build.0 = Debug|Any CPU
359+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|iPhone.ActiveCfg = Debug|Any CPU
360+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|iPhone.Build.0 = Debug|Any CPU
361+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
362+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
363+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|x64.ActiveCfg = Debug|Any CPU
364+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|x64.Build.0 = Debug|Any CPU
365+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|x86.ActiveCfg = Debug|Any CPU
366+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Debug|x86.Build.0 = Debug|Any CPU
367+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
368+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|Any CPU.Build.0 = Release|Any CPU
369+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|ARM.ActiveCfg = Release|Any CPU
370+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|ARM.Build.0 = Release|Any CPU
371+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|iPhone.ActiveCfg = Release|Any CPU
372+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|iPhone.Build.0 = Release|Any CPU
373+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
374+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
375+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|x64.ActiveCfg = Release|Any CPU
376+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|x64.Build.0 = Release|Any CPU
377+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|x86.ActiveCfg = Release|Any CPU
378+
{F7EBB910-0AA9-4683-878B-06108492F2F8}.Release|x86.Build.0 = Release|Any CPU
353379
EndGlobalSection
354380
GlobalSection(SolutionProperties) = preSolution
355381
HideSolutionNode = FALSE

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MvvmScarletToolkit
22

3-
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Insire/Maple/blob/master/license.md)
3+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Insire/MvvmScarletToolkit/blob/master/license.md)
44
[![NuGet](https://img.shields.io/nuget/v/MvvmScarletToolkit.svg?style=flat-square&label=nuget)](https://www.nuget.org/packages/MvvmScarletToolkit/)
55
[![Build status](https://dev.azure.com/SoftThorn/MvvmScarletToolkit/_apis/build/status/MvvmScarletToolkit-CD)](https://dev.azure.com/SoftThorn/MvvmScarletToolkit/_build/latest?definitionId=1)
66
[![CodeFactor](https://www.codefactor.io/repository/github/insire/mvvmscarlettoolkit/badge)](https://www.codefactor.io/repository/github/insire/mvvmscarlettoolkit)
@@ -24,6 +24,8 @@ Pre release nuget packages are available [here](https://pkgs.dev.azure.com/SoftT
2424
- INotifyPropertyChanged base classes for single instance viewmodels and collection viewmodels
2525
- Localization ViewModels (switching language without app restart)
2626
- Threadsafe busy state notifications via IBusyStack interface
27+
- ChangeTracker based on INotifyPropertyChanged
28+
- ChangeTracker based on PropertyChangedMessage\<T> (from CommunityToolkit.Mvvm)
2729
- Helper viewmodels for
2830
- paging
2931
- enums

src/Directory.Build.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
<PropertyGroup>
99
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
10-
<LangVersion>9.0</LangVersion>
10+
<LangVersion>10.0</LangVersion>
1111
<CodeAnalysisRuleSet>..\..\MvvmScarletToolkit.ruleset</CodeAnalysisRuleSet>
1212
</PropertyGroup>
1313

1414
<ItemGroup Condition=" '$(Configuration)'=='Debug' ">
15-
<PackageReference Include="Roslynator.Analyzers" Version="3.2.2">
15+
<PackageReference Include="Roslynator.Analyzers" Version="4.1.1">
1616
<PrivateAssets>all</PrivateAssets>
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
</PackageReference>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.ComponentModel;
3+
4+
namespace MvvmScarletToolkit
5+
{
6+
public interface IChangeTracker : IDisposable
7+
{
8+
/// <summary>
9+
/// Check if any tracked isntances were changed
10+
/// </summary>
11+
bool HasChanges();
12+
13+
/// <summary>
14+
/// Check if the provided <paramref name="instance"/> is being tracked and was changed
15+
/// </summary>
16+
/// <exception cref="ObjectDisposedException"></exception>
17+
/// <exception cref="ArgumentNullException"></exception>
18+
bool HasChanges<T>(T instance)
19+
where T : class, INotifyPropertyChanged;
20+
21+
/// <summary>
22+
/// Count how many properties of the provided <paramref name="instance"/> were changed
23+
/// </summary>
24+
/// <exception cref="ObjectDisposedException"></exception>
25+
/// <exception cref="ArgumentNullException"></exception>
26+
int CountChanges<T>(T instance)
27+
where T : class, INotifyPropertyChanged;
28+
29+
/// <summary>
30+
/// Track whether <paramref name="instance"/> raised <see cref="INotifyPropertyChanged.PropertyChanged"/>
31+
/// </summary>
32+
/// <param name="instance">The instance to track</param>
33+
/// <exception cref="ObjectDisposedException"></exception>
34+
/// <exception cref="ArgumentNullException"></exception>
35+
void Track<T>(T instance)
36+
where T : class, INotifyPropertyChanged;
37+
38+
/// <summary>
39+
/// Stops tracking all instances
40+
/// </summary>
41+
/// <exception cref="ObjectDisposedException"></exception>
42+
void StopAllTracking();
43+
44+
/// <summary>
45+
/// Stops tracking <paramref name="instance"/>
46+
/// </summary>
47+
/// <param name="instance"></param>
48+
/// <exception cref="ObjectDisposedException"></exception>
49+
/// <exception cref="ArgumentNullException"></exception>
50+
void StopTracking<T>(T instance)
51+
where T : class, INotifyPropertyChanged;
52+
53+
/// <summary>
54+
/// Discards any tracked changes
55+
/// </summary>
56+
/// <exception cref="ObjectDisposedException"></exception>
57+
void ClearAllChanges();
58+
59+
/// <summary>
60+
/// Discards any tracked changes for <paramref name="instance"/>
61+
/// </summary>
62+
/// <exception cref="ObjectDisposedException"></exception>
63+
/// <exception cref="ArgumentNullException"></exception>
64+
void ClearChanges<T>(T instance)
65+
where T : class, INotifyPropertyChanged;
66+
67+
/// <summary>
68+
/// Discards any new change notification, while the returned subscription is active
69+
/// </summary>
70+
/// <returns>the subscription</returns>
71+
/// <exception cref="ObjectDisposedException"></exception>
72+
IDisposable SuppressAllChanges();
73+
74+
/// <summary>
75+
/// Discards any new change notification for <paramref name="instance"/>, while the returned subscription is active
76+
/// </summary>
77+
/// <returns>the subscription</returns>
78+
/// <exception cref="ObjectDisposedException"></exception>
79+
/// <exception cref="ArgumentNullException"></exception>
80+
IDisposable SuppressChanges<T>(T instance)
81+
where T : class, INotifyPropertyChanged;
82+
}
83+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.ComponentModel;
3+
4+
namespace MvvmScarletToolkit
5+
{
6+
public interface IToolkitChangeTracker : IDisposable
7+
{
8+
/// <summary>
9+
/// Check if any tracked isntances were changed
10+
/// </summary>
11+
bool HasChanges();
12+
13+
/// <summary>
14+
/// Check if the provided <paramref name="instance"/> is being tracked and was changed
15+
/// </summary>
16+
/// <exception cref="ObjectDisposedException"></exception>
17+
/// <exception cref="ArgumentNullException"></exception>
18+
bool HasChanges<T>(T instance)
19+
where T : class, INotifyPropertyChanged;
20+
21+
/// <summary>
22+
/// Count how many properties of the provided <paramref name="instance"/> were changed
23+
/// </summary>
24+
/// <exception cref="ObjectDisposedException"></exception>
25+
/// <exception cref="ArgumentNullException"></exception>
26+
int CountChanges<T>(T instance)
27+
where T : class, INotifyPropertyChanged;
28+
29+
/// <summary>
30+
/// Track whether <paramref name="instance"/> raised <see cref="INotifyPropertyChanged.PropertyChanged"/>
31+
/// </summary>
32+
/// <param name="instance">The instance to track</param>
33+
/// <exception cref="ObjectDisposedException"></exception>
34+
/// <exception cref="ArgumentNullException"></exception>
35+
void Track<T, TPropertyType>(T instance)
36+
where T : class, INotifyPropertyChanged;
37+
38+
/// <summary>
39+
/// Stops tracking all instances
40+
/// </summary>
41+
/// <exception cref="ObjectDisposedException"></exception>
42+
void StopAllTracking();
43+
44+
/// <summary>
45+
/// Stops tracking <paramref name="instance"/>
46+
/// </summary>
47+
/// <param name="instance"></param>
48+
/// <exception cref="ObjectDisposedException"></exception>
49+
/// <exception cref="ArgumentNullException"></exception>
50+
void StopTracking<T>(T instance)
51+
where T : class, INotifyPropertyChanged;
52+
53+
/// <summary>
54+
/// Discards any tracked changes
55+
/// </summary>
56+
/// <exception cref="ObjectDisposedException"></exception>
57+
void ClearAllChanges();
58+
59+
/// <summary>
60+
/// Discards any tracked changes for <paramref name="instance"/>
61+
/// </summary>
62+
/// <exception cref="ObjectDisposedException"></exception>
63+
/// <exception cref="ArgumentNullException"></exception>
64+
void ClearChanges<T>(T instance)
65+
where T : class, INotifyPropertyChanged;
66+
67+
/// <summary>
68+
/// Discards any new change notification, while the returned subscription is active
69+
/// </summary>
70+
/// <returns>the subscription</returns>
71+
/// <exception cref="ObjectDisposedException"></exception>
72+
IDisposable SuppressAllChanges();
73+
74+
/// <summary>
75+
/// Discards any new change notification for <paramref name="instance"/>, while the returned subscription is active
76+
/// </summary>
77+
/// <returns>the subscription</returns>
78+
/// <exception cref="ObjectDisposedException"></exception>
79+
/// <exception cref="ArgumentNullException"></exception>
80+
IDisposable SuppressChanges<T>(T instance)
81+
where T : class, INotifyPropertyChanged;
82+
}
83+
}

src/MvvmScarletToolkit.Abstractions/MvvmScarletToolkit.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.244">
11+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.107">
1212
<PrivateAssets>all</PrivateAssets>
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
</PackageReference>

src/MvvmScarletToolkit.Commands/IScarletCommandBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.Toolkit.Mvvm.Messaging;
1+
using CommunityToolkit.Mvvm.Messaging;
22
using MvvmScarletToolkit.Commands;
33
using System;
44
using System.ComponentModel;

src/MvvmScarletToolkit.Commands/MvvmScarletToolkit.Commands.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
</PropertyGroup>
99

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

13-
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.244">
13+
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.107">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>

src/MvvmScarletToolkit.Incubator/MvvmScarletToolkit.Incubator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="DynamicData" Version="7.4.3" />
10+
<PackageReference Include="DynamicData" Version="7.9.1" />
1111
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
1212
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
1313
</ItemGroup>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
3+
namespace MvvmScarletToolkit.Observables.Tests
4+
{
5+
[ObservableRecipient]
6+
internal sealed partial class AttributedBroadCastViewModel : ObservableObject, ITestViewModel
7+
{
8+
[ObservableProperty]
9+
[NotifyPropertyChangedRecipients]
10+
private string _property;
11+
}
12+
}

0 commit comments

Comments
 (0)