|
|
|
@ -2,7 +2,6 @@ |
|
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System.Reactive.Linq; |
|
|
|
using System.Reactive.Subjects; |
|
|
|
|
|
|
|
namespace Avalonia.Styling |
|
|
|
@ -19,9 +18,8 @@ namespace Avalonia.Styling |
|
|
|
/// </remarks>
|
|
|
|
internal class ActivatedSubject : ActivatedObservable, ISubject<object>, IDescription |
|
|
|
{ |
|
|
|
private bool? _active; |
|
|
|
private bool _completed; |
|
|
|
private object _value; |
|
|
|
private object _pushValue; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ActivatedSubject"/> class.
|
|
|
|
@ -35,7 +33,6 @@ namespace Avalonia.Styling |
|
|
|
string description) |
|
|
|
: base(activator, source, description) |
|
|
|
{ |
|
|
|
Activator.Subscribe(ActivatorChanged, ActivatorError, ActivatorCompleted); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -46,53 +43,57 @@ namespace Avalonia.Styling |
|
|
|
get { return (ISubject<object>)base.Source; } |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Notifies all subscribed observers about the end of the sequence.
|
|
|
|
/// </summary>
|
|
|
|
public void OnCompleted() |
|
|
|
{ |
|
|
|
if (_active.Value && !_completed) |
|
|
|
Source.OnCompleted(); |
|
|
|
} |
|
|
|
|
|
|
|
public void OnError(Exception error) |
|
|
|
{ |
|
|
|
Source.OnError(error); |
|
|
|
} |
|
|
|
|
|
|
|
public void OnNext(object value) |
|
|
|
{ |
|
|
|
_pushValue = value; |
|
|
|
|
|
|
|
if (IsActive == true && !_completed) |
|
|
|
{ |
|
|
|
Source.OnCompleted(); |
|
|
|
Source.OnNext(_pushValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Notifies all subscribed observers with the exception.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="error">The exception to send to all subscribed observers.</param>
|
|
|
|
/// <exception cref="ArgumentNullException"><paramref name="error"/> is null.</exception>
|
|
|
|
public void OnError(Exception error) |
|
|
|
protected override void NotifyCompleted() |
|
|
|
{ |
|
|
|
if (_active.Value && !_completed) |
|
|
|
base.NotifyCompleted(); |
|
|
|
|
|
|
|
if (!_completed) |
|
|
|
{ |
|
|
|
Source.OnError(error); |
|
|
|
Source.OnCompleted(); |
|
|
|
_completed = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Notifies all subscribed observers with the value.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="value">The value to send to all subscribed observers.</param>
|
|
|
|
public void OnNext(object value) |
|
|
|
protected override void NotifyError(Exception error) |
|
|
|
{ |
|
|
|
_value = value; |
|
|
|
base.NotifyError(error); |
|
|
|
|
|
|
|
if (_active.Value && !_completed) |
|
|
|
if (!_completed) |
|
|
|
{ |
|
|
|
Source.OnNext(value); |
|
|
|
Source.OnError(error); |
|
|
|
_completed = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void ActivatorChanged(bool active) |
|
|
|
protected override void NotifyActive(bool active) |
|
|
|
{ |
|
|
|
bool first = !_active.HasValue; |
|
|
|
bool first = !IsActive.HasValue; |
|
|
|
|
|
|
|
_active = active; |
|
|
|
base.NotifyActive(active); |
|
|
|
|
|
|
|
if (!first) |
|
|
|
{ |
|
|
|
Source.OnNext(active ? _value : AvaloniaProperty.UnsetValue); |
|
|
|
Source.OnNext(active ? _pushValue : AvaloniaProperty.UnsetValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|