using System;
using System.Reactive.Concurrency;
using NodeNetwork.ViewModels;
using NodeNetwork.Views;
using ReactiveUI;
namespace NodeNetwork.Toolkit.ValueNode
{
///
/// A viewmodel for a node output that produces a value based on the inputs.
///
/// The type of object produced by this output.
public class ValueNodeOutputViewModel : NodeOutputViewModel
{
static ValueNodeOutputViewModel()
{
NNViewRegistrar.AddRegistration(() => new NodeOutputView(), typeof(IViewFor>));
}
#region Value
///
/// Observable that produces the value every time it changes.
///
public IObservable Value
{
get => _value;
set => this.RaiseAndSetIfChanged(ref _value, value);
}
private IObservable _value;
#endregion
#region CurrentValue
///
/// The latest value produced by this output.
///
public T CurrentValue => _currentValue.Value;
private readonly ObservableAsPropertyHelper _currentValue;
#endregion
public ValueNodeOutputViewModel()
{
this.WhenAnyObservable(vm => vm.Value).ToProperty(this, vm => vm.CurrentValue, out _currentValue, false, Scheduler.Immediate);
}
}
}