feat(observation): add WhenAnyDynamic and cover the runtime overloads - #86
Merged
Conversation
- Observe a property chain given as an Expression the caller built, across arities 1 to 12, with and without the distinct gate. - The chain is walked by reflection, so every overload carries [RequiresUnreferencedCode]. This is the one part of the observation surface that is not trimming- or AOT-safe. - Every arity observes each of its chains through one shared helper and differs only in how many it combines.
- Drop the class-level ExcludeFromCodeCoverage from ReactiveUIBindingExtensions. A partial's attribute applies to the merged type, so one attribute on the file holding the class declaration hid all fifteen partials - 154 real methods, of which only 17 are the refusing dispatch stubs it was written for. - Cover every arity of WhenChanged, WhenChanging, WhenAnyValue, WhenAny and WhenAnyObservable, and each binding stub's refusal. - Reach the overloads on the declaring class rather than as extension methods: written as an extension call the generated dispatch wins overload resolution and the runtime overload never runs.
- RequiresUnreferencedCode is a .NET 5+ type. On net462 the only one in reach is the runtime library's internal polyfill, which another assembly cannot apply, and no trim analyzer runs there to need the annotation. - One annotation per class covers every benchmark it holds, so the framework guard is a single conditional in each file.
… helper - Each overload is its signature and two lines: argument checks and the subscriptions move into a shared helper, so the reflection and the refusals are written once rather than once per arity. - Name the file for the arity-expanded surface it is, alongside the other *.WideArity.cs mixins. The repetition left is the twelve public signatures, which is what an arity-expanded API is.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #86 +/- ##
==========================================
+ Coverage 99.28% 99.48% +0.19%
==========================================
Files 232 246 +14
Lines 7597 10411 +2814
Branches 1080 1124 +44
==========================================
+ Hits 7543 10357 +2814
Misses 42 42
Partials 12 12 ☔ 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.



What kind of change does this PR introduce?
Feature, plus a test fix.
What is the new behavior?
WhenAnyDynamicobserves a property chain the caller built at run time, across arities 1 to 12.System.Linq.Expressions.Expressionrather than a lambda the compiler could read, sothe chain can come from a property name, a configuration entry, or a caller. Two overloads per arity, with
and without the distinct gate. Functionally equivalent to ReactiveUI's overloads of the same name.
[RequiresUnreferencedCode]. There is nothing for a generator to resolve in anexpression built at run time, so the chain is walked by reflection - this is the one part of the observation
surface that is not trimming- or AOT-safe, and a
PublishAotbuild reports each call site.The runtime observation and binding overloads are covered.
ReactiveUIBindingExtensionsno longer carries a class-level[ExcludeFromCodeCoverage].WhenChanged,WhenChanging,WhenAnyValue,WhenAnyandWhenAnyObservableis exercised,along with each binding stub's refusal to bind without a generated overload.
call the generated dispatch wins overload resolution and the runtime overload never runs, so the shape is
load-bearing and is noted in each test file.
What is the current behavior?
WhenAnyDynamichas no overload, so a chain only known at run time cannot be observed.A class-level
[ExcludeFromCodeCoverage]on one partial ofReactiveUIBindingExtensionsapplies to the mergedtype, so it covers all fifteen partials rather than the four holding the refusing dispatch stubs it was written
for. 154 methods are excluded from the coverage report.
What might this PR break?
None.
WhenAnyDynamicis new API, and the coverage attribute has no effect on emitted behaviour.Checklist
mainbranchAdditional information
WhenAnyDynamicis level with ReactiveUI's engine rather than faster, which is what a reflection walk on bothsides predicts. Single chain, 1,000 changes, .NET 10.0:
WhenChanged)WhenAnyDynamicWhenAnyDynamicMost of the gap to the generated path is the
IObservedChangehanded to the selector - 40 bytes pernotification, which the signature has to produce.
RxUiDynamicChainBaselinesits outside theReactiveUI.Bindingnamespace and types its selectors againstReactiveUI's
IObservedChange, so a call that resolved to this library's overload of the same name would failto compile rather than quietly benchmark the wrong engine.
Most of the diff is generated test bodies, one per arity. The hand-written files are
ReactiveUIBindingExtensions.WhenAnyDynamic.WideArity.cs,BindingDispatchStubTests.cs, the two benchmarkclasses, and the
README.mdsections.