Skip to content

Feature Enable WhenAny DistinctUntilChanged override #3966

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

Merged
merged 1 commit into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<PackageVersion Include="Roslynator.Analyzers" Version="4.12.11" />
<PackageVersion Include="Splat" Version="$(SplatVersion)" />
<PackageVersion Include="Splat.Autofac" Version="$(SplatVersion)" />
<PackageVersion Include="Splat.Drawing" Version="15.2.22" />
<PackageVersion Include="Splat.Drawing" Version="$(SplatVersion)" />
<PackageVersion Include="Splat.DryIoc" Version="$(SplatVersion)" />
<PackageVersion Include="Splat.Ninject" Version="$(SplatVersion)" />
<PackageVersion Include="stylecop.analyzers" Version="1.2.0-beta.556" />
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

36 changes: 25 additions & 11 deletions src/ReactiveUI/Mixins/ReactiveNotifyPropertyChangedMixin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,22 @@ public static class ReactiveNotifyPropertyChangedMixin
/// <typeparam name="TValue">The value type.</typeparam>
/// <param name="item">The source object to observe properties of.</param>
/// <param name="property">An Expression representing the property (i.e.
/// 'x => x.SomeProperty.SomeOtherProperty'.</param>
/// 'x =&gt; x.SomeProperty.SomeOtherProperty'.</param>
/// <param name="beforeChange">If True, the Observable will notify
/// immediately before a property is going to change.</param>
/// <param name="skipInitial">If true, the Observable will not notify
/// with the initial value.</param>
/// <returns>An Observable representing the property change
/// notifications for the given property.</returns>
/// <param name="isDistinct">if set to <c>true</c> [is distinct].</param>
/// <returns>
/// An Observable representing the property change
/// notifications for the given property.
/// </returns>
public static IObservable<IObservedChange<TSender, TValue>> ObservableForProperty<TSender, TValue>(
this TSender? item,
Expression<Func<TSender, TValue>> property,
bool beforeChange = false,
bool skipInitial = true)
bool skipInitial = true,
bool isDistinct = true)
{
property.ArgumentNullExceptionThrowIfNull(nameof(property));

Expand All @@ -68,7 +72,8 @@ public static IObservable<IObservedChange<TSender, TValue>> ObservableForPropert
item,
property.Body,
beforeChange,
skipInitial);
skipInitial,
isDistinct);
}

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

/// <summary>
/// Creates a observable which will subscribe to the each property and sub property
/// specified in the Expression. eg It will subscribe to x => x.Property1.Property2.Property3
/// specified in the Expression. eg It will subscribe to x =&gt; x.Property1.Property2.Property3
/// each property in the lambda expression. It will then provide updates to the last value in the chain.
/// </summary>
/// <typeparam name="TSender">The type of the origin of the expression chain.</typeparam>
/// <typeparam name="TValue">The end value we want to subscribe to.</typeparam>
/// <param name="source">The object where we start the chain.</param>
/// <param name="expression">A expression which will point towards the property.</param>
/// <param name="beforeChange">If we are interested in notifications before the property value is changed.</param>
/// <param name="skipInitial">If we don't want to get a notification about the default value of the property.</param>
/// <param name="suppressWarnings">If true, no warnings should be logged.</param>
/// <typeparam name="TSender">The type of the origin of the expression chain.</typeparam>
/// <typeparam name="TValue">The end value we want to subscribe to.</typeparam>
/// <returns>A observable which notifies about observed changes.</returns>
/// <param name="isDistinct">if set to <c>true</c> [is distinct].</param>
/// <returns>
/// A observable which notifies about observed changes.
/// </returns>
/// <exception cref="InvalidCastException">If we cannot cast from the target value from the specified last property.</exception>
public static IObservable<IObservedChange<TSender, TValue>> SubscribeToExpressionChain<TSender, TValue>(
this TSender? source,
Expression? expression,
bool beforeChange = false,
bool skipInitial = true,
bool suppressWarnings = false) // TODO: Create Test
bool suppressWarnings = false,
bool isDistinct = true) // TODO: Create Test
{
IObservable<IObservedChange<object?, object?>> notifier =
Observable.Return(new ObservedChange<object?, object?>(null, null, source));
Expand Down Expand Up @@ -150,7 +159,12 @@ public static IObservable<IObservedChange<TSender, TValue>> SubscribeToExpressio
return new ObservedChange<TSender, TValue>(source!, expression, (TValue)val!);
});

return r.DistinctUntilChanged(x => x.Value);
if (isDistinct)
{
return r.DistinctUntilChanged(x => x.Value);
}

return r;
}

private static IObservable<IObservedChange<object?, object?>> NestedObservedChanges(Expression expression, IObservedChange<object?, object?> sourceChange, bool beforeChange, bool suppressWarnings)
Expand Down
3 changes: 3 additions & 0 deletions src/ReactiveUI/ReactiveUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@
<None Update="VariadicTemplates.tt" Generator="TextTemplatingFileGenerator" LastGenOutput="VariadicTemplates.cs" />
<Compile Update="VariadicTemplates.cs" DesignTime="True" AutoGen="true" DependentUpon="VariadicTemplates.tt" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
</Project>
Loading
Loading