Skip to content

Commit

Permalink
Merge pull request AvaloniaUI#8442 from AvaloniaUI/fixes/empty-batch-…
Browse files Browse the repository at this point in the history
…update

Fix empty batch nested updates.
  • Loading branch information
maxkatz6 authored and danwalmsley committed Jul 6, 2022
1 parent 7695205 commit 3edae5a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/Avalonia.Base/ValueStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,6 @@ public bool End()
values.Remove(entry.property);
}
}
else
{
throw new AvaloniaInternalException("Value could not be found at the end of batch update.");
}

// If a new batch update was started while ending this one, abort.
if (_batchUpdateCount > 0)
Expand Down
30 changes: 30 additions & 0 deletions tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_BatchUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,36 @@ public void Can_Bind_Completed_Binding_Back_To_Original_Value_When_Ending_Batch_
Assert.Equal("foo", notifications[1].NewValue);
}

[Fact]
public void Can_Run_Empty_Batch_Update_When_Ending_Batch_Update()
{
var target = new TestClass();
var raised = 0;
var notifications = new List<AvaloniaPropertyChangedEventArgs>();

target.Foo = "foo";
target.Bar = "bar";

target.BeginBatchUpdate();
target.ClearValue(TestClass.FooProperty);
target.ClearValue(TestClass.BarProperty);
target.PropertyChanged += (sender, e) =>
{
if (e.Property == TestClass.BarProperty)
{
target.BeginBatchUpdate();
target.EndBatchUpdate();
}

++raised;
};
target.EndBatchUpdate();

Assert.Null(target.Foo);
Assert.Null(target.Bar);
Assert.Equal(2, raised);
}

public class TestClass : AvaloniaObject
{
public static readonly StyledProperty<string> FooProperty =
Expand Down

0 comments on commit 3edae5a

Please sign in to comment.