feat: follow WinForms host properties through ReactiveUI.Binding's ObservedProperty - #506
Merged
Merged
Conversation
…servedProperty With ReactiveUI.Binding 8.4.0 or later, the [RoutedControlHost] and [ViewModelControlHost] hosts follow DefaultContent, Content, ViewModel, Router and ViewContractObservable through Binding's ObservedProperty, in the flavour their view API comes from: Create for WhenAnyValue, and Then and Switch for WhenAnyObservable, with static lambdas. ObservedProperty is not intercepted, so it works from generated code, and keeps WhenAnyValue's semantics. With an older ReactiveUI.Binding, or none, the hosts keep following their own PropertyChanged, and the new ControlHostAnalyzer reports RXUISG0022 (Info) on each host. The generator and the analyzer decide from the same ViewApiRules file, which now also picks the view API. There is no package dependency on Binding: the decision follows the Binding the project references.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #506 +/- ##
==========================================
+ Coverage 96.70% 96.75% +0.05%
==========================================
Files 74 76 +2
Lines 3759 3824 +65
Branches 531 544 +13
==========================================
+ Hits 3635 3700 +65
Misses 124 124 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With ReactiveUI.Binding 8.4.0 or later, the WinForms hosts follow their own properties through Binding's
ObservedProperty, withWhenAnyValuesemantics.[RoutedControlHost]and[ViewModelControlHost]hosts useObservedPropertywhen the project's ReactiveUI.Binding has it.CreatereplacesWhenAnyValueforDefaultContent,ContentandViewModel, andThenplusSwitchreplaceWhenAnyObservableforRouter.CurrentViewModelandViewContractObservable, in the flavour the host's view API comes from.PropertyChanged. A newControlHostAnalyzerreports RXUISG0022 (Info) on each such host.ViewApiRules, which looks forObservedPropertyin the referenced Binding flavour and now also picks the view API.Why
Generated code has to keep
WhenAnysemantics without calling an API ReactiveUI.Binding intercepts.PropertyChangedfollowing; ReactiveUI.Binding 8.4.0 addsObservedProperty, a non-intercepted, AOT-safe observation API withWhenAnyValue's semantics, for exactly this case.Breaking changes
None. Hosts on ReactiveUI.Binding 8.4.0 or later follow their properties through Binding's observation, including any registered observation provider; other hosts are generated as in 4.1.0.
How this was verified
New tests compile and run both hosts against the real ReactiveUI.Binding 8.4.0, lean and
.Reactive, showing the default content and then the routed or hosted view; the analyzer is tested with and withoutObservedProperty.ObservedProperty) and with 8.1.0 (the fallback).Notes for the reviewer
Start with
ViewApiRules.csand the threeAppend*members inControlHostExtensions.cs.ControlHostWriteris renamedControlHostExtensions, as it now holds an extension block.ExcludeAssetsalone did not.Checklist