fix(generator): declare observation helpers for every dispatch file - #57
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #57 +/- ##
==========================================
+ Coverage 97.61% 97.63% +0.01%
==========================================
Files 227 228 +1
Lines 7752 7772 +20
Branches 1062 1066 +4
==========================================
+ Hits 7567 7588 +21
Misses 143 143
+ Partials 42 41 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- Move the KVO and WinUI helper class declarations out of the WhenChanged dispatch file into ObservationHelpers.g.cs, so binding dispatch files that reference them compile (fixes #48) - Key the declarations to the detected types rather than the call sites, which keeps them a superset of the references and stops a second observation file declaring them twice - Ship the generator and analyzer in ReactiveUI.Binding and ReactiveUI.Binding.Reactive, matching the documented install story - Stop packing the same assemblies in ReactiveUI.Binding.SourceGenerators: a second copy loads as a second generator and emits every dispatch file twice - Cover NSObject sources and targets through BindOneWay and BindTwoWay
- Extract the declaration loop into a static AppendHelperDeclarations so it can be exercised without a source production context. - Cover both paths, including a kind no plugin answers to: the pipeline cannot produce one, but a generator that threw on an unexpected kind would fail the consumer's build rather than merely generate less. - Pin the invariant that makes that case impossible - every kind the selection yields resolves back to a plugin, so a new plugin whose kind did not round-trip would be caught rather than silently declaring nothing.
glennawatson
force-pushed
the
fix/issue-48-kvo-helper-emission
branch
from
August 2, 2026 03:26
804b4ad to
f727861
Compare
|
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.



What kind of change does this PR introduce?
Bug fix (source generator emission and packaging).
What is the new behavior?
__KVOObserver,__KVOObservable<T>and the WinUI equivalents) are declared once, in a dedicatedObservationHelpers.g.cs, for any compilation that detects a type requiring them. Every dispatch file can now use them, so binding a KVO type throughBindTwoWay,BindOneWay,Bind,OneWayBind,BindCommand,BindInteraction,WhenAnyorWhenAnyObservablecompiles.ReactiveUI.BindingandReactiveUI.Binding.Reactivenow carry the generator, so referencing the runtime package alone is enough. This is what the documentation already promised.What is the current behavior?
Closes #48
WhenChanged,WhenChangingorWhenAnyValuecall anywhere, generated dispatch code referencing__KVOObservable<T>while nothing declared it. The build failed withCS0246: The type or namespace name '__KVOObservable<>' could not be found. Only the observation code generator declared the helpers.WhenChanged,WhenChangingandWhenAnyValueon a KVO type declared the helpers more than once, because the observation generator runs once per API. That producedCS0102. This was latent and is fixed by the same change.ReactiveUI.Binding.SourceGeneratorsby hand despite the documentation stating the generator is included automatically.What might this PR break?
ReactiveUI.Binding.SourceGeneratorsno longer carries the generator assemblies; it keeps only its props file and is now a compatibility package. This is deliberate: shipping the generator in both runtime packages while also shipping it here caused a consumer referencing more than one of them to load the generator twice, which failed the build withCS0111,CS0101andCS0579. Existing consumers that reference the SourceGenerators package continue to build, because the generator arrives through the runtime package they already reference. Consider deprecating or unlisting that package separately.PlatformDetectionSnapshotTests.NSObject_Detectednow uses the shared Apple platform stub and asserts the generated output compiles. Its previous minimal stub could snapshot helper code that does not compile.Checklist
mainbranchAdditional information
Verification:
NSObjectsource used throughBindOneWayandBindTwoWay. Both fail onmainwith the reporter's exact error and pass here.ReactiveUI.Binding.Reactiveplus anNSObjectsource withBindTwoWay(clean build, helpers emitted).