Browse Source
Merge pull request #1895 from AvaloniaUI/fixes/dispose-completed-binding
Don't throw when disposing completed binding.
pull/1896/head
Jeremy Koritzinsky
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
29 additions and
6 deletions
-
src/Avalonia.Base/PriorityBindingEntry.cs
-
src/Avalonia.Base/PriorityLevel.cs
-
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Binding.cs
|
|
|
@ -50,6 +50,11 @@ namespace Avalonia |
|
|
|
get; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets a value indicating whether the binding has completed.
|
|
|
|
/// </summary>
|
|
|
|
public bool HasCompleted { get; private set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The current value of the binding.
|
|
|
|
/// </summary>
|
|
|
|
@ -129,6 +134,8 @@ namespace Avalonia |
|
|
|
|
|
|
|
private void Completed() |
|
|
|
{ |
|
|
|
HasCompleted = true; |
|
|
|
|
|
|
|
if (Dispatcher.UIThread.CheckAccess()) |
|
|
|
{ |
|
|
|
_owner.Completed(this); |
|
|
|
|
|
|
|
@ -112,12 +112,16 @@ namespace Avalonia |
|
|
|
|
|
|
|
return Disposable.Create(() => |
|
|
|
{ |
|
|
|
Bindings.Remove(node); |
|
|
|
entry.Dispose(); |
|
|
|
|
|
|
|
if (entry.Index >= ActiveBindingIndex) |
|
|
|
if (!entry.HasCompleted) |
|
|
|
{ |
|
|
|
ActivateFirstBinding(); |
|
|
|
Bindings.Remove(node); |
|
|
|
|
|
|
|
entry.Dispose(); |
|
|
|
|
|
|
|
if (entry.Index >= ActiveBindingIndex) |
|
|
|
{ |
|
|
|
ActivateFirstBinding(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@ -479,6 +479,18 @@ namespace Avalonia.Base.UnitTests |
|
|
|
Assert.False(source.SetterCalled); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Disposing_Completed_Binding_Does_Not_Throw() |
|
|
|
{ |
|
|
|
var target = new Class1(); |
|
|
|
var source = new Subject<string>(); |
|
|
|
var subscription = target.Bind(Class1.FooProperty, source); |
|
|
|
|
|
|
|
source.OnCompleted(); |
|
|
|
|
|
|
|
subscription.Dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns an observable that returns a single value but does not complete.
|
|
|
|
/// </summary>
|
|
|
|
@ -595,4 +607,4 @@ namespace Avalonia.Base.UnitTests |
|
|
|
public bool SetterCalled { get; private set; } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|