Skip to content

Commit fc79b8c

Browse files
authored
Feature Enable WhenAny DistinctUntilChanged override (#3966)
<!-- Please be sure to read the [Contribute](https://github.com/reactiveui/reactiveui#contribute) section of the README --> **What kind of change does this PR introduce?** <!-- Bug fix, feature, docs update, ... --> feature closes #3846 **What is the current behavior?** <!-- You can also link to an open issue here. --> #3846 **What is the new behavior?** <!-- If this is a feature change --> Update Splat.Drawing package reference Enable WhenAny / WhenAnyValue / WhenAnyDynamic to include a DistinctUntilChanged override Enable ObservableForProperty and SubscribeToExpressionChain to include a DistinctUntilChanged override **What might this PR break?** None expected as is an additional override set to a default value of true **Please check if the PR fulfills these requirements** - [ ] Tests for the changes have been added (for bug fixes / features) - [ ] Docs have been added / updated (for bug fixes / features) **Other information**:
1 parent 510d73c commit fc79b8c

8 files changed

+2150
-2016
lines changed

src/Directory.Packages.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<PackageVersion Include="Roslynator.Analyzers" Version="4.12.11" />
2828
<PackageVersion Include="Splat" Version="$(SplatVersion)" />
2929
<PackageVersion Include="Splat.Autofac" Version="$(SplatVersion)" />
30-
<PackageVersion Include="Splat.Drawing" Version="15.2.22" />
30+
<PackageVersion Include="Splat.Drawing" Version="$(SplatVersion)" />
3131
<PackageVersion Include="Splat.DryIoc" Version="$(SplatVersion)" />
3232
<PackageVersion Include="Splat.Ninject" Version="$(SplatVersion)" />
3333
<PackageVersion Include="stylecop.analyzers" Version="1.2.0-beta.556" />

src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.DotNet8_0.verified.txt

+45-45
Large diffs are not rendered by default.

src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.DotNet9_0.verified.txt

+45-45
Large diffs are not rendered by default.

src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.Net4_7.verified.txt

+45-45
Large diffs are not rendered by default.

src/ReactiveUI/Mixins/ReactiveNotifyPropertyChangedMixin.cs

+25-11
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,22 @@ public static class ReactiveNotifyPropertyChangedMixin
3434
/// <typeparam name="TValue">The value type.</typeparam>
3535
/// <param name="item">The source object to observe properties of.</param>
3636
/// <param name="property">An Expression representing the property (i.e.
37-
/// 'x => x.SomeProperty.SomeOtherProperty'.</param>
37+
/// 'x =&gt; x.SomeProperty.SomeOtherProperty'.</param>
3838
/// <param name="beforeChange">If True, the Observable will notify
3939
/// immediately before a property is going to change.</param>
4040
/// <param name="skipInitial">If true, the Observable will not notify
4141
/// with the initial value.</param>
42-
/// <returns>An Observable representing the property change
43-
/// notifications for the given property.</returns>
42+
/// <param name="isDistinct">if set to <c>true</c> [is distinct].</param>
43+
/// <returns>
44+
/// An Observable representing the property change
45+
/// notifications for the given property.
46+
/// </returns>
4447
public static IObservable<IObservedChange<TSender, TValue>> ObservableForProperty<TSender, TValue>(
4548
this TSender? item,
4649
Expression<Func<TSender, TValue>> property,
4750
bool beforeChange = false,
48-
bool skipInitial = true)
51+
bool skipInitial = true,
52+
bool isDistinct = true)
4953
{
5054
property.ArgumentNullExceptionThrowIfNull(nameof(property));
5155

@@ -68,7 +72,8 @@ public static IObservable<IObservedChange<TSender, TValue>> ObservableForPropert
6872
item,
6973
property.Body,
7074
beforeChange,
71-
skipInitial);
75+
skipInitial,
76+
isDistinct);
7277
}
7378

7479
/// <summary>
@@ -104,24 +109,28 @@ public static IObservable<TRet> ObservableForProperty<TSender, TValue, TRet>(
104109

105110
/// <summary>
106111
/// Creates a observable which will subscribe to the each property and sub property
107-
/// specified in the Expression. eg It will subscribe to x => x.Property1.Property2.Property3
112+
/// specified in the Expression. eg It will subscribe to x =&gt; x.Property1.Property2.Property3
108113
/// each property in the lambda expression. It will then provide updates to the last value in the chain.
109114
/// </summary>
115+
/// <typeparam name="TSender">The type of the origin of the expression chain.</typeparam>
116+
/// <typeparam name="TValue">The end value we want to subscribe to.</typeparam>
110117
/// <param name="source">The object where we start the chain.</param>
111118
/// <param name="expression">A expression which will point towards the property.</param>
112119
/// <param name="beforeChange">If we are interested in notifications before the property value is changed.</param>
113120
/// <param name="skipInitial">If we don't want to get a notification about the default value of the property.</param>
114121
/// <param name="suppressWarnings">If true, no warnings should be logged.</param>
115-
/// <typeparam name="TSender">The type of the origin of the expression chain.</typeparam>
116-
/// <typeparam name="TValue">The end value we want to subscribe to.</typeparam>
117-
/// <returns>A observable which notifies about observed changes.</returns>
122+
/// <param name="isDistinct">if set to <c>true</c> [is distinct].</param>
123+
/// <returns>
124+
/// A observable which notifies about observed changes.
125+
/// </returns>
118126
/// <exception cref="InvalidCastException">If we cannot cast from the target value from the specified last property.</exception>
119127
public static IObservable<IObservedChange<TSender, TValue>> SubscribeToExpressionChain<TSender, TValue>(
120128
this TSender? source,
121129
Expression? expression,
122130
bool beforeChange = false,
123131
bool skipInitial = true,
124-
bool suppressWarnings = false) // TODO: Create Test
132+
bool suppressWarnings = false,
133+
bool isDistinct = true) // TODO: Create Test
125134
{
126135
IObservable<IObservedChange<object?, object?>> notifier =
127136
Observable.Return(new ObservedChange<object?, object?>(null, null, source));
@@ -150,7 +159,12 @@ public static IObservable<IObservedChange<TSender, TValue>> SubscribeToExpressio
150159
return new ObservedChange<TSender, TValue>(source!, expression, (TValue)val!);
151160
});
152161

153-
return r.DistinctUntilChanged(x => x.Value);
162+
if (isDistinct)
163+
{
164+
return r.DistinctUntilChanged(x => x.Value);
165+
}
166+
167+
return r;
154168
}
155169

156170
private static IObservable<IObservedChange<object?, object?>> NestedObservedChanges(Expression expression, IObservedChange<object?, object?> sourceChange, bool beforeChange, bool suppressWarnings)

src/ReactiveUI/ReactiveUI.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,7 @@
6969
<None Update="VariadicTemplates.tt" Generator="TextTemplatingFileGenerator" LastGenOutput="VariadicTemplates.cs" />
7070
<Compile Update="VariadicTemplates.cs" DesignTime="True" AutoGen="true" DependentUpon="VariadicTemplates.tt" />
7171
</ItemGroup>
72+
<ItemGroup>
73+
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
74+
</ItemGroup>
7275
</Project>

0 commit comments

Comments
 (0)