-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from AvaloniaCommunity/feature/Sync-Stable-v8…
….1.97.11xx Publish v8.1.97.11073
- Loading branch information
Showing
15 changed files
with
154 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
|
||
namespace Prism.Common | ||
{ | ||
internal static class Stubs | ||
{ | ||
public static readonly Action Nop = () => { }; | ||
public static readonly Action<Exception> Throw = ex => { throw ex; }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using Avalonia.Reactive; | ||
using Prism.Common; | ||
|
||
namespace Prism.Extensions | ||
{ | ||
internal static class ObservableExtensions | ||
{ | ||
/// <summary> | ||
/// Subscribes an element handler to an observable sequence. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the elements in the source sequence.</typeparam> | ||
/// <param name="source">Observable sequence to subscribe to.</param> | ||
/// <param name="onNext">Action to invoke for each element in the observable sequence.</param> | ||
/// <returns><see cref="IDisposable"/> object used to unsubscribe from the observable sequence.</returns> | ||
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="onNext"/> is <c>null</c>.</exception> | ||
public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext) | ||
{ | ||
if (source == null) | ||
{ | ||
throw new ArgumentNullException(nameof(source)); | ||
} | ||
|
||
if (onNext == null) | ||
{ | ||
throw new ArgumentNullException(nameof(onNext)); | ||
} | ||
|
||
// | ||
// [OK] Use of unsafe Subscribe: non-pretentious constructor for an observer; this overload is not to be used internally. | ||
// | ||
return source.Subscribe/*Unsafe*/(new AnonymousObserver<T>(onNext, Stubs.Throw, Stubs.Nop)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using Avalonia; | ||
using Avalonia; | ||
using Prism.Extensions; | ||
using System; | ||
|
||
namespace Prism.Regions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/Avalonia/Prism.Avalonia.Tests/Interactivity/ObservableBehaviorFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Avalonia; | ||
using Xunit; | ||
using Prism.Extensions; | ||
|
||
namespace Prism.Avalonia.Tests.Interactivity | ||
{ | ||
public class ObservableBehaviorFixture | ||
{ | ||
[Fact] | ||
public void SubscribeWorksOnIObservableWithLambda() | ||
{ | ||
var targetUIElement = new TestAvaloniaObject(); | ||
targetUIElement.Test = "123"; | ||
|
||
Assert.Equal("123", targetUIElement.OutTest); | ||
} | ||
} | ||
|
||
class TestAvaloniaObject : AvaloniaObject | ||
{ | ||
/// <summary> | ||
/// The property to subscribe on. | ||
/// </summary> | ||
public static readonly StyledProperty<string> TestProperty = | ||
AvaloniaProperty.Register<TestAvaloniaObject, string>("Test"); | ||
|
||
/// <summary> | ||
/// Gets or sets a value to the TestProperty. | ||
/// </summary> | ||
public string Test | ||
{ | ||
get { return (string)GetValue(TestProperty); } | ||
set { SetValue(TestProperty, value); } | ||
} | ||
|
||
/// <summary> | ||
/// The out test property to check after TestProperty change | ||
/// </summary> | ||
public string OutTest { get; set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="TestAvaloniaObject"/>. | ||
/// </summary> | ||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. | ||
public TestAvaloniaObject() | ||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. | ||
{ | ||
TestProperty.Changed.Subscribe(args => OnPropertyChanged(args)); | ||
} | ||
|
||
private void OnPropertyChanged(AvaloniaPropertyChangedEventArgs<string> args) | ||
{ | ||
OutTest = args.NewValue.Value; | ||
} | ||
} | ||
} |