Repository navigation
fix: generate bindings in views that [IViewFor] makes implement IViewFor<T> - #558
Merged
Merged
Conversation
…For<T>
- Read [IViewFor<T>] and [IViewFor("Name")] by metadata name, and declare the IViewFor<T> interface, ViewModel, BindingRoot and IViewFor.ViewModel they add.
- Follow that generator's rules: only partial classes deriving from a WPF, Windows Forms, WinUI, MAUI, Avalonia or Uno control, with no BindingRoot on a Windows Forms view.
- Keep both interfaces on a type marked [IReactiveObject] and [IViewFor].
- Run the real IViewForGenerator beside the binding generator in the contract tests.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #558 +/- ##
=======================================
Coverage 99.09% 99.09%
=======================================
Files 487 487
Lines 19240 19275 +35
Branches 2893 2903 +10
=======================================
+ Hits 19065 19100 +35
Misses 175 175 ☔ 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
Bindings in a view marked
[IViewFor<T>]or[IViewFor("Name")]now get generated code, so they no longer need theUnsafeoverloads or raise RXUIBIND021.[IViewFor]and sees theIViewFor<T>interface and theViewModel,BindingRootandIViewFor.ViewModelproperties that ReactiveUI.SourceGenerators adds to the view.BindingRoot.[IReactiveObject]and[IViewFor]keeps both interfaces.Why
No generator sees another generator's output. The binding generator already declares the members
[Reactive],[BindableDerivedList]and the other attributes write, so call sites that bind them can be read. It did not do this for[IViewFor], so in a view that getsIViewFor<T>from the attribute,this.OneWayBind(ViewModel, ...)had noViewModeland no interface to bind against. Nothing was generated, RXUIBIND021 was reported, and the call neededOneWayBindUnsafe. A view that derives fromReactiveUserControl<T>was not affected, which is why the problem appeared after switching to[IViewFor<T>].Closes #557
Breaking changes
None
How this was verified
The contract tests run ReactiveUI.SourceGenerators' real
IViewForGeneratorbeside the binding generator. They bind a[BindableDerivedList]list and a[Reactive]property from views marked with each form of[IViewFor], then run the bindings in both runtime flavours, with and without interceptors. With the new declarations removed, those bindings throw the "No generated OneWayBind dispatch" error from the issue. The declaration tests cover each rule above. The Linux examples suite passes, including the native AOT publish ofsetup/aot.Notes for the reviewer
Start with
SourceGeneratorsMemberExtractor.ExtractIViewFor. It reuses the view locator'sResolveViewModelandReferencedViewNamespace, so the view model and the runtime flavour are found the same way the view locator finds them. InSourceGeneratorsCompilation.Add, a member can now carry an interface and properties together, and a second interface on the same type is appended rather than replacing the first.Checklist