-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Add Reactiveproperty<T>.Subscribe(Observer<T> observer, bool riseOnSubscription = true)
overload
#215
Comments
It would be beneficial to add an argument to the |
Is there any design reasons to put this inside constructor? Imagine that you have some class which expose it's Maybe it is more convenient when owner decides how owned |
I get where you're coming from about losing the guarantee of a signal on subscription. I suggested it as an option, hoping that it could also be considered to help achieve the outcome you were after. However, it seems like that's not what you're looking for. |
I think that making overload have cons such as At the same time adding constructor parameter at least guarantee subscribe behaviour for owner. But the main problem remains: subscribers still must "know" what they subscribe on. |
Maybe it should not raise callback during subcribtion no matter how convenient it may be? |
Agree, it is better to introduce extension method that will invoke callback with current value (if there is any) |
Fixes Cysharp#215 Add `Subscribe(Observer<T> observer, bool riseOnSubscription = true)` overload to `ReactiveProperty<T>` class. * Add a new `Subscribe` method overload with `riseOnSubscription` parameter to `ReactiveProperty<T>` class in `src/R3/ReactiveProperty.cs`. * Update `SubscribeCore` method in `ReactiveProperty<T>` class to conditionally call `observer.OnNext(currentValue)` based on `riseOnSubscription` parameter. * Add new `Subscribe` method overloads with `riseOnSubscription` parameter to `ObservableSubscribeExtensions` class in `src/R3/ObservableSubscribeExtensions.cs`. * Add unit tests for the new `Subscribe` method overload with `riseOnSubscription` parameter in `ReactiveProperty<T>` class in `tests/R3.Tests/ReactivePropertyTest.cs`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Cysharp/R3/issues/215?shareId=XXXX-XXXX-XXXX-XXXX).
For new devs like me it is often confusing when callback rises immediately after subscription even there is now changes. It is even more confusing because when you use
PairWise
beforeSubscribe
it will not rise callback right after subscription.There is code in
ReactiveProperty.cs
which callsOnNext()
without any condition.There is some advices to use
Skip(1)
for such situations but again it may lead to unexpected behavior whenPairWise
used, so actual value change will be ignored 1 time in this case.The text was updated successfully, but these errors were encountered: