Fix ToReadOnlyReactiveProperty()
behavior
#279
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.
The current code path of
ToReadOnlyReactiveProperty()
is as follows.When calling
ToReadOnlyReactiveProperty()
onReadOnlyReactiveProperty<T>
, the instance method is called. This returns the instance itself.When calling
ToReadOnlyReactiveProperty()
onObservable<T>
, the extension method is called. Here, if the source isReadOnlyReactiveProperty<T>
, the instance is returned as is.The problem here is that if the source is
ReadOnlyReactiveProperty<T>
, even ifinitialValue
andequalityComparer
are specified as arguments, they are ignored. This is unintuitive and not desirable behavior.Therefore, this PR changes the code path as follows.
When calling
ToReadOnlyReactiveProperty()
onReadOnlyReactiveProperty<T>
, the instance method is called.When calling
ToReadOnlyReactiveProperty()
onObservable<T>
, the extension method is called. Here, if source isReadOnlyReactiveProperty<T>
and it is the overload without arguments, the instance is returned as is.This ensures that an instance is always created when an argument is specified, so it will work correctly even if source is
ReadOnlyReactiveProperty<T>
.