fix: stop the WinForms hosts relying on WhenAny, and generate them in their own namespace - #504
Merged
Merged
Conversation
… their own namespace
The [RoutedControlHost] and [ViewModelControlHost] constructors called
WhenAny, WhenAnyValue and WhenAnyObservable. With ReactiveUI built on
ReactiveUI.Binding, those calls are dispatched by Binding's generator, which
cannot see call sites in another generator's output, so constructing a host
threw "No generated WhenAny dispatch matched this call site".
The hosts now follow their own properties through a nested PropertyObservable
over their PropertyChanged event, switching to the selected observable on each
change as WhenAnyObservable does. The events call
SubscribePropertyChangedEvents and SubscribePropertyChangingEvents on first
subscription, as ReactiveObject and the [IReactiveObject] generator do; without
that ReactiveUI never raised them for a host. No generated code now calls an
API ReactiveUI.Binding has to intercept.
The hosts were also written into `namespace {TargetNamespace}` as-is, so a host
in the global namespace produced an unnamed namespace and a separate type, and
a nested host produced a top-level type. They now open the namespace and any
containing types as the other generators do.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #504 +/- ##
==========================================
+ Coverage 96.45% 96.55% +0.10%
==========================================
Files 71 72 +1
Lines 3578 3653 +75
Branches 506 506
==========================================
+ Hits 3451 3527 +76
+ Misses 127 126 -1 ☔ 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
The WinForms
[RoutedControlHost]and[ViewModelControlHost]hosts no longer callWhenAny, and are generated into the host's own namespace and containing types.PropertyObservableover theirPropertyChangedevent. It switches to the selected observable on each change, asWhenAnyObservabledoes, so the hosts no longer callWhenAny,WhenAnyValueorWhenAnyObservable.PropertyChangedandPropertyChangingevents callSubscribePropertyChangedEventsandSubscribePropertyChangingEventson first subscription. This is whatReactiveObjectand the[IReactiveObject]generator do; without it ReactiveUI never raised the events for a host.namespace {TargetNamespace}as-is.WhenAny*,Bind,OneWayBind,BindCommandorToPropertycall.Why
With ReactiveUI built on ReactiveUI.Binding, constructing either host threw
No generated WhenAny dispatch matched this call site.WhenAnycalls it can see in source, and a generator cannot see another generator's output, so the calls in the generated host constructors had no dispatch.Breaking changes
None. The hosts' public members are unchanged.
How this was verified
New tests compile both hosts against ReactiveUI and the desktop stubs, construct them, and check they show their default content and then the routed or hosted view; they also cover global-namespace and nested hosts and assert no
WhenAnyin the output..Reactiveflavours, throws the dispatch error with 4.0.0 and shows the default content, routed view and view-model view with this change.Notes for the reviewer
Start with
ControlHostWriter.cs, then the two hosts'WriteConstructor/WriteSetupBindings.TestCompilationReferences.WindowsDesktopStubsnow enumerates a copy of the control collection, as the real collection tolerates removal during enumeration, which the view-model host relies on.RxState.DefaultExceptionHandleronce up front: ReactiveUI sets its initialized flag before assigning the handler, so two hosts constructed concurrently on a cold start can readnull. That race is in ReactiveUI and is not fixed here.Checklist