Skip to content

Commit

Permalink
Avoid throwing exceptions after resource disposal (#501)
Browse files Browse the repository at this point in the history
Changed the PropertyChanged method in the PropertyChangedObservable class to return instead of throwing an InvalidOperationException when _isDisposed is true. Added a return check in the SourcePropertyChangedEventHandler method of the PropertyPathNode class when _isDisposed is true. Changed the PropertyChanged method in the SimplePropertyObservable class to return instead of throwing an InvalidOperationException when _isDisposed is true.
  • Loading branch information
runceel authored Jan 27, 2025
1 parent eb92dc2 commit 6c76130
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Subscription(INotifyPropertyChanged notifyPropertyChanged, IObserver<Prop

private void PropertyChanged(object? _, PropertyChangedEventArgs e)
{
if (_isDisposed) throw new InvalidOperationException();
if (_isDisposed) return;
_observer.OnNext(e);
}

Expand Down
1 change: 1 addition & 0 deletions Source/ReactiveProperty.Core/Internals/PropertyPathNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public bool SetPropertyPathValue(object? value)

private void SourcePropertyChangedEventHandler(object? sender, PropertyChangedEventArgs e)
{
if (_isDisposed) return;
if (e.PropertyName == PropertyName || string.IsNullOrEmpty(e.PropertyName))
{
Next?.UpdateSource(GetPropertyValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public Subscription(TSubject subject, Func<TSubject, TProperty> accessor, string

private void PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (_isDisposed) return;
if (e.PropertyName != _propertyName && !string.IsNullOrEmpty(e.PropertyName)) return;
if (_isDisposed) throw new InvalidOperationException();

try
{
Expand Down

0 comments on commit 6c76130

Please sign in to comment.