Skip to content

Commit 7ca89e7

Browse files
committed
Remove internal System.Reactive usage. Only keep old visible API to avoid breaking changes.
1 parent 38dce08 commit 7ca89e7

File tree

12 files changed

+77
-33
lines changed

12 files changed

+77
-33
lines changed

src/Avalonia.Controls.TreeDataGrid/Avalonia.Controls.TreeDataGrid.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111
<ItemGroup>
1212
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
13-
14-
<PackageReference Include="System.Reactive" Version="5.0.0" />
13+
14+
<PackageReference Include="System.Reactive" Version="6.0.0" />
1515
</ItemGroup>
1616
</Project>

src/Avalonia.Controls.TreeDataGrid/Experimental/Data/Core/TypedBindingExpression`2.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.Collections.Specialized;
33
using System.ComponentModel;
4-
using System.Reactive.Subjects;
54
using Avalonia.Data;
5+
using Avalonia.Reactive;
66
using Avalonia.Utilities;
77

88
#nullable enable
@@ -19,7 +19,7 @@ namespace Avalonia.Experimental.Data.Core
1919
/// instantiated on an object.
2020
/// </remarks>
2121
public class TypedBindingExpression<TIn, TOut> : LightweightObservableBase<BindingValue<TOut>>,
22-
ISubject<BindingValue<TOut>>,
22+
IObserver<BindingValue<TOut>>,
2323
IDescription
2424
where TIn : class
2525
{
@@ -91,7 +91,7 @@ void IObserver<BindingValue<TOut>>.OnError(Exception error)
9191
protected override void Initialize()
9292
{
9393
_flags &= ~Flags.RootHasFired;
94-
_rootSourceSubsciption = _rootSource.Subscribe(RootChanged);
94+
_rootSourceSubsciption = _rootSource.Subscribe(new AnonymousObserver<TIn?>(RootChanged));
9595
_flags |= Flags.Initialized;
9696
}
9797

src/Avalonia.Controls.TreeDataGrid/Experimental/Data/ObservableEx.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System;
2-
using System.Reactive.Disposables;
2+
using Avalonia.Experimental.Data.Core;
33

44
namespace Avalonia.Experimental.Data
55
{

src/Avalonia.Controls.TreeDataGrid/Experimental/Data/TypedBinding`2.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Reactive.Disposables;
32
using Avalonia.Data;
43
using Avalonia.Experimental.Data.Core;
54
using Avalonia.Reactive;

src/Avalonia.Controls.TreeDataGrid/Models/TreeDataGrid/CheckBoxCell.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using System;
2-
using System.Reactive.Subjects;
3-
using System.Reflection;
42
using Avalonia.Data;
3+
using Avalonia.Reactive;
54

65
namespace Avalonia.Controls.Models.TreeDataGrid
76
{
87
public class CheckBoxCell : NotifyingBase, ICell, IDisposable
98
{
10-
private readonly ISubject<BindingValue<bool?>>? _binding;
9+
private readonly IObserver<BindingValue<bool?>>? _binding;
1110
private readonly IDisposable? _subscription;
1211
private bool? _value;
1312

@@ -18,19 +17,29 @@ public CheckBoxCell(bool? value)
1817
}
1918

2019
public CheckBoxCell(
21-
ISubject<BindingValue<bool?>> binding,
20+
IObserver<BindingValue<bool?>> bindingObserver,
21+
IObservable<BindingValue<bool?>> bindingObservable,
2222
bool isReadOnly,
2323
bool isThreeState)
2424
{
25-
_binding = binding;
25+
_binding = bindingObserver;
2626
IsReadOnly = isReadOnly;
2727
IsThreeState = isThreeState;
2828

29-
_subscription = binding.Subscribe(x =>
29+
_subscription = bindingObservable.Subscribe(new AnonymousObserver<BindingValue<bool?>>(x =>
3030
{
3131
if (x.HasValue)
3232
Value = x.Value;
33-
});
33+
}));
34+
}
35+
36+
[Obsolete("ISubject<> might be removed in the future versions.")]
37+
public CheckBoxCell(
38+
System.Reactive.Subjects.ISubject<BindingValue<bool?>> binding,
39+
bool isReadOnly,
40+
bool isThreeState)
41+
: this(binding, binding, isReadOnly, isThreeState)
42+
{
3443
}
3544

3645
public bool CanEdit => false;

src/Avalonia.Controls.TreeDataGrid/Models/TreeDataGrid/CheckBoxColumn.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public CheckBoxColumn(
6868

6969
public override ICell CreateCell(IRow<TModel> row)
7070
{
71-
return new CheckBoxCell(CreateBindingExpression(row.Model), Binding.Write is null, IsThreeState);
71+
var expression = CreateBindingExpression(row.Model);
72+
return new CheckBoxCell(expression, expression, Binding.Write is null, IsThreeState);
7273
}
7374

7475
private static Func<TModel, bool?> ToNullable(Expression<Func<TModel, bool>> getter)

src/Avalonia.Controls.TreeDataGrid/Models/TreeDataGrid/ColumnBase`2.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq.Expressions;
55
using Avalonia.Experimental.Data;
66
using Avalonia.Experimental.Data.Core;
7-
using Avalonia.Reactive;
87

98
namespace Avalonia.Controls.Models.TreeDataGrid
109
{

src/Avalonia.Controls.TreeDataGrid/Models/TreeDataGrid/ExpanderCell.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.ComponentModel;
3-
using System.Reactive.Disposables;
43
using Avalonia.Data;
54
using Avalonia.Experimental.Data.Core;
5+
using Avalonia.Reactive;
66

77
namespace Avalonia.Controls.Models.TreeDataGrid
88
{
@@ -12,7 +12,7 @@ public class ExpanderCell<TModel> : NotifyingBase,
1212
where TModel : class
1313
{
1414
private readonly ICell _inner;
15-
private readonly CompositeDisposable _subscription = new();
15+
private readonly IDisposable _subscription;
1616

1717
public ExpanderCell(
1818
ICell inner,
@@ -24,15 +24,19 @@ public ExpanderCell(
2424
Row = row;
2525
row.PropertyChanged += RowPropertyChanged;
2626

27-
_subscription.Add(showExpander.Subscribe(x => Row.UpdateShowExpander(this, x)));
28-
27+
var expanderSubscription = showExpander.Subscribe(new AnonymousObserver<bool>(x => Row.UpdateShowExpander(this, x)));
2928
if (isExpanded is not null)
3029
{
31-
_subscription.Add(isExpanded.Subscribe(x =>
30+
var isExpandedSubscription = isExpanded.Subscribe(new AnonymousObserver<BindingValue<bool>>(x =>
3231
{
3332
if (x.HasValue)
3433
IsExpanded = x.Value;
3534
}));
35+
_subscription = new CompositeDisposable(expanderSubscription, isExpandedSubscription);
36+
}
37+
else
38+
{
39+
_subscription = expanderSubscription;
3640
}
3741
}
3842

src/Avalonia.Controls.TreeDataGrid/Models/TreeDataGrid/TextCell.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using System.Diagnostics.CodeAnalysis;
5-
using System.Reactive.Subjects;
65
using Avalonia.Data;
76
using Avalonia.Media;
7+
using Avalonia.Reactive;
88

99
namespace Avalonia.Controls.Models.TreeDataGrid
1010
{
1111
public class TextCell<T> : NotifyingBase, ITextCell, IDisposable, IEditableObject
1212
{
13-
private readonly ISubject<BindingValue<T>>? _binding;
13+
private readonly IObserver<BindingValue<T>>? _binding;
1414
private readonly IDisposable? _subscription;
1515
[AllowNull] private T? _value;
1616
[AllowNull] private T? _cancelValue;
@@ -24,19 +24,29 @@ public TextCell(T? value)
2424
}
2525

2626
public TextCell(
27-
ISubject<BindingValue<T>> binding,
27+
IObserver<BindingValue<T>> bindingSubject,
28+
IObservable<BindingValue<T>> bindingObservable,
2829
bool isReadOnly,
2930
ITextCellOptions? options = null)
3031
{
31-
_binding = binding;
32+
_binding = bindingSubject;
3233
IsReadOnly = isReadOnly;
3334
_options = options;
3435

35-
_subscription = binding.Subscribe(x =>
36+
_subscription = bindingObservable.Subscribe(new AnonymousObserver<BindingValue<T>>(x =>
3637
{
3738
if (x.HasValue)
3839
Value = x.Value;
39-
});
40+
}));
41+
}
42+
43+
[Obsolete("ISubject<> might be removed in the future versions.")]
44+
public TextCell(
45+
System.Reactive.Subjects.ISubject<BindingValue<T>> binding,
46+
bool isReadOnly,
47+
ITextCellOptions? options = null)
48+
: this(binding, binding, isReadOnly, options)
49+
{
4050
}
4151

4252
public bool CanEdit => !IsReadOnly;

src/Avalonia.Controls.TreeDataGrid/Models/TreeDataGrid/TextColumn.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public TextColumn(
6262

6363
public override ICell CreateCell(IRow<TModel> row)
6464
{
65-
return new TextCell<TValue?>(CreateBindingExpression(row.Model), Binding.Write is null, Options);
65+
var expression = CreateBindingExpression(row.Model);
66+
return new TextCell<TValue?>(expression, expression, Binding.Write is null, Options);
6667
}
6768

6869
string? ITextSearchableColumn<TModel>.SelectValue(TModel model)

0 commit comments

Comments
 (0)