Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ToReadOnlyReactiveProperty() behavior #279

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AnnulusGames
Copy link

@AnnulusGames AnnulusGames commented Dec 6, 2024

The current code path of ToReadOnlyReactiveProperty() is as follows.

  1. When calling ToReadOnlyReactiveProperty() on ReadOnlyReactiveProperty<T>, the instance method is called. This returns the instance itself.

  2. When calling ToReadOnlyReactiveProperty() on Observable<T>, the extension method is called. Here, if the source is ReadOnlyReactiveProperty<T>, the instance is returned as is.

The problem here is that if the source is ReadOnlyReactiveProperty<T>, even if initialValue and equalityComparer are specified as arguments, they are ignored. This is unintuitive and not desirable behavior.

Therefore, this PR changes the code path as follows.

  1. When calling ToReadOnlyReactiveProperty() on ReadOnlyReactiveProperty<T>, the instance method is called.

  2. When calling ToReadOnlyReactiveProperty() on Observable<T>, the extension method is called. Here, if source is ReadOnlyReactiveProperty<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>.

@AnnulusGames
Copy link
Author

AnnulusGames commented Dec 6, 2024

However, as pointed out in #263, it might be better to always create a new instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant