Skip to content

Commit 37fa90a

Browse files
authored
feat!: run property observation and binding on ReactiveUI.Binding (#4475)
## Summary ReactiveUI's property observation and binding now run on ReactiveUI.Binding and its source generator. View location, view hosts, templates, routing, activation and validation presentation stay in ReactiveUI. - `WhenAny*`, `WhenAnyValue`, `ObservableForProperty`, `Bind`, `OneWayBind`, `BindTo`, `BindCommand`, `InvokeCommand`, `BindInteraction` and `ToProperty` come from `ReactiveUI.Binding`. Most calls are generated at build time, and an `...Unsafe` overload covers a path the generator cannot read. - `ObservableAsPropertyHelper<T>` and `ToProperty` are generated by ReactiveUI.Binding, with the same public members. - `ReactiveUI` depends on `ReactiveUI.Binding` 7.8.0, and `ReactiveUI.Reactive` on `ReactiveUI.Binding.Reactive`. The generator, analyzer and build props flow to consuming projects. The WPF, WinForms and MAUI packages bring the matching Binding platform package. - Packaged build props add the Binding namespace and keep ReactiveUI's view locator authoritative, so existing `using ReactiveUI;` code keeps compiling. - ReactiveUI's own reflection-based engine is removed: `Reflection`, the expression helpers, the observation providers, the platform command binders, the binder implementations, the Apple `NSDate` converters and the `TypeDescriptor` fallback converter. - ReactiveUI's hand-written `IReactiveObject` hosts and platform base types raise `PropertyChanged` for any subscriber, because generated observation listens to that event. - `ReactiveUI`, `ReactiveUI.Reactive`, `ReactiveUI.Core`, `ReactiveUI.Routing` and `ReactiveUI.Drawing` target only the frameworks they have platform code for. Consumers on the dropped targets resolve the plain .NET build, which is the same code. - The README links to the [migration guide](https://reactiveui.net/documentation/upgrading/reactiveui-binding-migration), which explains what to change and what behaves differently. ## Why ReactiveUI kept two engines for the same job: its own reflection-based observation and binding, and ReactiveUI.Binding, which generates the code at build time and runs under trimming and NativeAOT. Keeping one engine removes about 190,000 lines and the reflection paths that needed trimming attributes. ## Breaking changes - The removed types listed under "Removed types" in the [migration guide](https://reactiveui.net/documentation/upgrading/reactiveui-binding-migration) are gone. The binding methods keep their names and come from `ReactiveUI.Binding`. - `Interaction.Handle` returns `Task<TOutput>` instead of `IObservable<TOutput>`. - A type that implements `IReactiveObject` by hand raises `PropertyChanged` only after `SubscribePropertyChangedEvents()`. The migration guide shows the event accessor to use. Types deriving from `ReactiveObject` need nothing. - Behavioural differences: converters are chosen by declared type, and a conversion delegate cannot refuse a value. Every binding writes on the thread that owns the view. A broken view-model path leaves the view's value in place. The migration guide lists them all. ## How this was verified The full test suite runs against the released ReactiveUI.Binding 7.8.0 on Linux and on real Windows, including the WPF, WinForms, WinUI and MAUI projects. Tests of the removed engine are gone, and integration tests cover the replacement. The full solution also builds on Windows with the Apple and WinUI targets. A NativeAOT console consumer of the packed packages publishes with no trim or AOT warnings and runs. ## Notes for the reviewer Most of the diff is deletion of the old engine and its tests, and regenerated public API baselines; those are safe to skim. Start with `src/ReactiveShim.props`, the packaged `buildTransitive` props, and `src/Directory.Packages.props` for how Binding reaches consumers. Then read the platform base types' event accessors and the WinForms hosts. The target framework changes are in `src/Directory.Build.props` and the five project files; the dropped targets compiled no code of their own. The user-facing summary is the [migration guide](https://reactiveui.net/documentation/upgrading/reactiveui-binding-migration), in reactiveui/website#999. ## Checklist - [x] I have read the [Contribute guide](https://www.reactiveui.net/contribute/index.html) - [x] The PR title follows [Conventional Commits](https://www.conventionalcommits.org/) - [x] Tests cover this change, or the summary says why they do not - [x] New or changed public API has XML documentation
1 parent 8ba04db commit 37fa90a

852 files changed

Lines changed: 5978 additions & 202998 deletions

File tree

Some content is hidden

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

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ bandwidth.
205205

206206
[Become a sponsor](https://github.com/sponsors/reactivemarbles).
207207

208+
## Migrating bindings to ReactiveUI.Binding
209+
210+
ReactiveUI runs `WhenAnyValue`, `Bind`, `OneWayBind`, `BindCommand` and `ToProperty` on
211+
[ReactiveUI.Binding](https://github.com/reactiveui/ReactiveUI.Binding.SourceGenerators), which writes the code for
212+
each binding while your project builds. Most code keeps compiling unchanged. The
213+
[migration guide](https://reactiveui.net/documentation/upgrading/reactiveui-binding-migration) covers the calls that
214+
need an `Unsafe` twin, hand-written `IReactiveObject` types, and the behavior that changed.
215+
208216
## Migration from Xamarin and .NET 8 MAUI
209217

210218
### Xamarin Users

‎src/Directory.Build.props‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,15 @@
112112
<ReactiveUITestingUITargets>$(ReactiveUITestingTargets)</ReactiveUITestingUITargets>
113113
<ReactiveUITestingUITargets Condition="$([MSBuild]::IsOsPlatform('Windows'))">net8.0-windows10.0.19041.0;net9.0-windows10.0.19041.0;net10.0-windows10.0.19041.0;net11.0-windows10.0.19041.0</ReactiveUITestingUITargets>
114114

115-
<!-- Start with core targets available on all platforms -->
116-
<ReactiveUIFinalTargetFrameworks>$(ReactiveUICoreTargets)</ReactiveUIFinalTargetFrameworks>
115+
<!-- Libraries with no platform-specific code: every platform consumes the plain .NET or .NET Framework build. -->
116+
<ReactiveUIPortableTargetFrameworks>$(ReactiveUICoreTargets);$(ReactiveUIFrameworkTargets)</ReactiveUIPortableTargetFrameworks>
117117

118-
<!-- Add Android targets (available on all platforms with Android SDK) -->
119-
<ReactiveUIFinalTargetFrameworks>$(ReactiveUIFinalTargetFrameworks);$(ReactiveUIAndroidTargets)</ReactiveUIFinalTargetFrameworks>
118+
<!-- Libraries with Windows-specific code only. -->
119+
<ReactiveUIPortableWindowsTargetFrameworks>$(ReactiveUIPortableTargetFrameworks);$(ReactiveUIWindowsTargets)</ReactiveUIPortableWindowsTargetFrameworks>
120120

121-
<!-- Add Windows-specific targets (.NET Framework and Windows-specific TFMs) on Windows, or anywhere EnableWindowsTargeting is set (reference-only compile on Linux/macOS). -->
122-
<ReactiveUIFinalTargetFrameworks>$(ReactiveUIFinalTargetFrameworks);$(ReactiveUIFrameworkTargets);$(ReactiveUIWindowsTargets)</ReactiveUIFinalTargetFrameworks>
123-
124-
<!-- Add Apple targets on macOS and Windows -->
125-
<ReactiveUIFinalTargetFrameworks Condition="$([MSBuild]::IsOsPlatform('Windows')) or $([MSBuild]::IsOsPlatform('OSX'))">$(ReactiveUIFinalTargetFrameworks);$(ReactiveUIAppleTargets)</ReactiveUIFinalTargetFrameworks>
121+
<!-- Libraries with Android and Apple platform code. Apple targets build on macOS and Windows only. -->
122+
<ReactiveUIPlatformTargetFrameworks>$(ReactiveUIPortableTargetFrameworks);$(ReactiveUIAndroidTargets)</ReactiveUIPlatformTargetFrameworks>
123+
<ReactiveUIPlatformTargetFrameworks Condition="$([MSBuild]::IsOsPlatform('Windows')) or $([MSBuild]::IsOsPlatform('OSX'))">$(ReactiveUIPlatformTargetFrameworks);$(ReactiveUIAppleTargets)</ReactiveUIPlatformTargetFrameworks>
126124

127125
<!-- Final target frameworks for tests/benchmarks (modern .NET only, with platform-specific additions) -->
128126
<ReactiveUIFinalModernTargetFrameworks>$(ReactiveUIModernTargets)</ReactiveUIFinalModernTargetFrameworks>

‎src/Directory.Packages.props‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<PropertyGroup Label="Shared Version Variables">
88
<SplatVersion>21.0.0</SplatVersion>
99
<PrimitivesVersion>8.2.0</PrimitivesVersion>
10+
<BindingVersion>7.10.1</BindingVersion>
1011
<TUnitVersion>1.69.0</TUnitVersion>
1112
<!-- StyleSharp.Analyzers, PerformanceSharp.Analyzers and SecuritySharp.Analyzers ship from the
1213
same release pipeline and always share a version. -->
@@ -56,6 +57,17 @@
5657
<PackageVersion Include="ReactiveUI.Primitives.Blazor.Reactive" Version="$(PrimitivesVersion)"/>
5758
</ItemGroup>
5859

60+
<ItemGroup Label="ReactiveUI Binding">
61+
<PackageVersion Include="ReactiveUI.Binding" Version="$(BindingVersion)"/>
62+
<PackageVersion Include="ReactiveUI.Binding.Reactive" Version="$(BindingVersion)"/>
63+
<PackageVersion Include="ReactiveUI.Binding.Wpf" Version="$(BindingVersion)"/>
64+
<PackageVersion Include="ReactiveUI.Binding.Wpf.Reactive" Version="$(BindingVersion)"/>
65+
<PackageVersion Include="ReactiveUI.Binding.WinForms" Version="$(BindingVersion)"/>
66+
<PackageVersion Include="ReactiveUI.Binding.WinForms.Reactive" Version="$(BindingVersion)"/>
67+
<PackageVersion Include="ReactiveUI.Binding.Maui" Version="$(BindingVersion)"/>
68+
<PackageVersion Include="ReactiveUI.Binding.Maui.Reactive" Version="$(BindingVersion)"/>
69+
</ItemGroup>
70+
5971
<ItemGroup Label="Rx Ecosystem">
6072
<PackageVersion Include="DynamicData" Version="9.4.33"/>
6173
<PackageVersion Include="Splat" Version="$(SplatVersion)"/>

‎src/ReactiveShim.props‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
ReactiveUI.Primitives types. The *.Reactive leaves are excluded; they rebind below. -->
3232
<ItemGroup Condition="'$(RxReactiveSeam)' != 'true'">
3333
<Using Include="ReactiveUI.Primitives.RxVoid" Alias="RxVoid"/>
34+
<Using Include="ReactiveUI.Binding" Condition="'$(MSBuildProjectName)' != 'ReactiveUI.Core'" />
35+
<Using Include="ReactiveUI.Binding.Expressions" Condition="'$(MSBuildProjectName)' != 'ReactiveUI.Core'" />
3436
<!-- Scheduler seam: the shared source names only ISequencer (the type), the Sequencer static
3537
(Immediate/Default/CurrentThread/Normalize), TaskPoolSequencer, and the Schedule(...) extensions.
3638
Lean binds them to ReactiveUI.Primitives.Concurrency; the *.Reactive leaves rebind to System.Reactive
@@ -69,6 +71,9 @@
6971
<Using Include="ReactiveUI.Reactive.Internal" />
7072
<Using Include="ReactiveUI.Reactive.Builder" />
7173
<Using Include="ReactiveUI.Reactive.Interfaces" />
74+
<!-- ReactiveUI.Binding types shifted for .Reactive build -->
75+
<Using Include="ReactiveUI.Binding.Reactive" />
76+
<Using Include="ReactiveUI.Binding.Reactive.Expressions" />
7277
<Using Include="ReactiveUI.Primitives.Signals" />
7378
<!-- Reactive-shim counterpart of the lean leaf's ReactiveUI.Primitives.Advanced import: the same
7479
seam-neutral concrete signal classes, flipped to the ReactiveUI.Primitives.Reactive.Advanced namespace. -->
@@ -103,4 +108,13 @@
103108
<Analyzer Remove="@(Analyzer)" Condition="$([System.String]::Copy('%(Analyzer.FileName)').Contains('ReactiveUI.Primitives.R3Bridge.Generator')) or $([System.String]::Copy('%(Analyzer.FileName)').Contains('ReactiveUI.Primitives.SystemReactiveBridge.Generator'))"/>
104109
</ItemGroup>
105110
</Target>
111+
112+
<!-- ReactiveUI.Core brings the lean Binding assembly into .Reactive projects for its public contracts.
113+
NuGet also flows the lean generator despite ExcludeAssets. WPF markup projects copy analyzer items
114+
without NuGetPackageId metadata, so select the lean package by its path in both project shapes. -->
115+
<Target Name="StripLeanBindingAnalyzers" BeforeTargets="CoreCompile" Condition="'$(RxReactiveSeam)' == 'true'">
116+
<ItemGroup>
117+
<Analyzer Remove="@(Analyzer)" Condition="$([System.String]::Copy('%(Analyzer.FullPath)').Contains('reactiveui.binding')) and !$([System.String]::Copy('%(Analyzer.FullPath)').Contains('reactiveui.binding.reactive'))"/>
118+
</ItemGroup>
119+
</Target>
106120
</Project>

‎src/ReactiveUI.AndroidX.Reactive/PublicAPI/net10.0-android36.0/PublicAPI.txt‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ namespace ReactiveUI.Reactive.AndroidX
4343
public System.IDisposable SuppressChangeNotifications() { }
4444
}
4545
[System.Diagnostics.DebuggerDisplay("{ViewModel}")]
46-
public class ReactiveAppCompatActivity<TViewModel> : ReactiveUI.Reactive.AndroidX.ReactiveAppCompatActivity, ReactiveUI.IViewFor<TViewModel>, ReactiveUI.Reactive.ICanActivate where TViewModel : class
46+
public class ReactiveAppCompatActivity<TViewModel> : ReactiveUI.Reactive.AndroidX.ReactiveAppCompatActivity, ReactiveUI.Binding.Reactive.IViewFor<TViewModel>, ReactiveUI.Reactive.ICanActivate where TViewModel : class
4747
{
4848
protected ReactiveAppCompatActivity() { }
49-
object? ReactiveUI.IViewFor.ViewModel { get; set; }
49+
object? ReactiveUI.Binding.Reactive.IViewFor.ViewModel { get; set; }
5050
public TViewModel? ViewModel { get; set; }
5151
}
5252
[System.Diagnostics.DebuggerDisplay("{Activated}, {Deactivated}")]
@@ -71,10 +71,10 @@ namespace ReactiveUI.Reactive.AndroidX
7171
public System.IDisposable SuppressChangeNotifications() { }
7272
}
7373
[System.Diagnostics.DebuggerDisplay("{ViewModel}")]
74-
public class ReactiveDialogFragment<TViewModel> : ReactiveUI.Reactive.AndroidX.ReactiveDialogFragment, ReactiveUI.IViewFor<TViewModel>, ReactiveUI.Reactive.ICanActivate where TViewModel : class
74+
public class ReactiveDialogFragment<TViewModel> : ReactiveUI.Reactive.AndroidX.ReactiveDialogFragment, ReactiveUI.Binding.Reactive.IViewFor<TViewModel>, ReactiveUI.Reactive.ICanActivate where TViewModel : class
7575
{
7676
protected ReactiveDialogFragment() { }
77-
object? ReactiveUI.IViewFor.ViewModel { get; set; }
77+
object? ReactiveUI.Binding.Reactive.IViewFor.ViewModel { get; set; }
7878
public TViewModel? ViewModel { get; set; }
7979
}
8080
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
@@ -100,10 +100,10 @@ namespace ReactiveUI.Reactive.AndroidX
100100
public System.IDisposable SuppressChangeNotifications() { }
101101
}
102102
[System.Diagnostics.DebuggerDisplay("{ViewModel}")]
103-
public class ReactiveFragment<TViewModel> : ReactiveUI.Reactive.AndroidX.ReactiveFragment, ReactiveUI.IViewFor<TViewModel>, ReactiveUI.Reactive.ICanActivate where TViewModel : class
103+
public class ReactiveFragment<TViewModel> : ReactiveUI.Reactive.AndroidX.ReactiveFragment, ReactiveUI.Binding.Reactive.IViewFor<TViewModel>, ReactiveUI.Reactive.ICanActivate where TViewModel : class
104104
{
105105
protected ReactiveFragment() { }
106-
object? ReactiveUI.IViewFor.ViewModel { get; set; }
106+
object? ReactiveUI.Binding.Reactive.IViewFor.ViewModel { get; set; }
107107
public TViewModel? ViewModel { get; set; }
108108
}
109109
[System.Diagnostics.DebuggerDisplay("{Activated}, {Deactivated}")]
@@ -134,10 +134,10 @@ namespace ReactiveUI.Reactive.AndroidX
134134
public System.IDisposable SuppressChangeNotifications() { }
135135
}
136136
[System.Diagnostics.DebuggerDisplay("{ViewModel}")]
137-
public class ReactiveFragmentActivity<TViewModel> : ReactiveUI.Reactive.AndroidX.ReactiveFragmentActivity, ReactiveUI.IViewFor<TViewModel>, ReactiveUI.Reactive.ICanActivate where TViewModel : class
137+
public class ReactiveFragmentActivity<TViewModel> : ReactiveUI.Reactive.AndroidX.ReactiveFragmentActivity, ReactiveUI.Binding.Reactive.IViewFor<TViewModel>, ReactiveUI.Reactive.ICanActivate where TViewModel : class
138138
{
139139
protected ReactiveFragmentActivity() { }
140-
object? ReactiveUI.IViewFor.ViewModel { get; set; }
140+
object? ReactiveUI.Binding.Reactive.IViewFor.ViewModel { get; set; }
141141
public TViewModel? ViewModel { get; set; }
142142
}
143143
[System.Diagnostics.DebuggerDisplay("Count = {Count}")]
@@ -179,11 +179,11 @@ namespace ReactiveUI.Reactive.AndroidX
179179
public System.IDisposable SuppressChangeNotifications() { }
180180
}
181181
[System.Diagnostics.DebuggerDisplay("{ViewModel}")]
182-
public abstract class ReactivePreferenceFragment<TViewModel> : ReactiveUI.Reactive.AndroidX.ReactivePreferenceFragment, ReactiveUI.IViewFor<TViewModel>, ReactiveUI.Reactive.ICanActivate where TViewModel : class
182+
public abstract class ReactivePreferenceFragment<TViewModel> : ReactiveUI.Reactive.AndroidX.ReactivePreferenceFragment, ReactiveUI.Binding.Reactive.IViewFor<TViewModel>, ReactiveUI.Reactive.ICanActivate where TViewModel : class
183183
{
184184
protected ReactivePreferenceFragment() { }
185185
protected ReactivePreferenceFragment(in nint handle, Android.Runtime.JniHandleOwnership ownership) { }
186-
object? ReactiveUI.IViewFor.ViewModel { get; set; }
186+
object? ReactiveUI.Binding.Reactive.IViewFor.ViewModel { get; set; }
187187
public TViewModel? ViewModel { get; set; }
188188
}
189189
[System.Diagnostics.DebuggerDisplay("ItemCount = {ItemCount}")]
@@ -204,7 +204,7 @@ namespace ReactiveUI.Reactive.AndroidX
204204
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Android property discovery discovery uses reflection that may require dynamic code generation.")]
205205
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Android property discovery uses reflection over generated resource types that may be trimmed.")]
206206
[System.Diagnostics.DebuggerDisplay("{ViewModel}")]
207-
public class ReactiveRecyclerViewViewHolder<TViewModel> : AndroidX.RecyclerView.Widget.RecyclerView.ViewHolder, ReactiveUI.IReactiveNotifyPropertyChanged<ReactiveUI.Reactive.AndroidX.ReactiveRecyclerViewViewHolder<TViewModel>>, ReactiveUI.IReactiveObject, ReactiveUI.IViewFor<TViewModel>, ReactiveUI.Reactive.ICanActivate, ReactiveUI.Reactive.ILayoutViewHost where TViewModel : class, ReactiveUI.IReactiveObject
207+
public class ReactiveRecyclerViewViewHolder<TViewModel> : AndroidX.RecyclerView.Widget.RecyclerView.ViewHolder, ReactiveUI.Binding.Reactive.IViewFor<TViewModel>, ReactiveUI.IReactiveNotifyPropertyChanged<ReactiveUI.Reactive.AndroidX.ReactiveRecyclerViewViewHolder<TViewModel>>, ReactiveUI.IReactiveObject, ReactiveUI.Reactive.ICanActivate, ReactiveUI.Reactive.ILayoutViewHost where TViewModel : class, ReactiveUI.IReactiveObject
208208
{
209209
protected ReactiveRecyclerViewViewHolder(Android.Views.View view) { }
210210
public System.IObservable<System.Reactive.Unit> Activated { get; }
@@ -220,7 +220,7 @@ namespace ReactiveUI.Reactive.AndroidX
220220
public System.IObservable<System.Reactive.Unit> Deactivated { get; }
221221
public System.IObservable<int> LongClicked { get; }
222222
public System.IObservable<TViewModel?> LongClickedWithViewModel { get; }
223-
object? ReactiveUI.IViewFor.ViewModel { get; set; }
223+
object? ReactiveUI.Binding.Reactive.IViewFor.ViewModel { get; set; }
224224
public System.IObservable<int> Selected { get; }
225225
public System.IObservable<TViewModel?> SelectedWithViewModel { get; }
226226
[System.Runtime.Serialization.IgnoreDataMember]

0 commit comments

Comments
 (0)
⌂ 换网址