using System.Reactive.Linq; using DynamicData; using NodeNetwork.Toolkit.ValueNode; using NodeNetwork.ViewModels; using NodeNetwork.Views; using ReactiveUI; namespace ExampleCalculatorApp.ViewModels.Nodes { public class SubtractionNodeViewModel : NodeViewModel { static SubtractionNodeViewModel() { Splat.Locator.CurrentMutable.Register(() => new NodeView(), typeof(IViewFor)); } public ValueNodeInputViewModel Input1 { get; } public ValueNodeInputViewModel Input2 { get; } public ValueNodeOutputViewModel Output { get; } public SubtractionNodeViewModel() { Name = "Subtract"; Input1 = new ValueNodeInputViewModel { Name = "A", Editor = new IntegerValueEditorViewModel() }; Inputs.Add(Input1); Input2 = new ValueNodeInputViewModel { Name = "B", Editor = new IntegerValueEditorViewModel() }; Inputs.Add(Input2); var subtract = this.WhenAnyValue(vm => vm.Input1.Value, vm => vm.Input2.Value) .Select(_ => Input1.Value != null && Input2.Value != null ? Input1.Value - Input2.Value : null); Output = new ValueNodeOutputViewModel { Name = "A - B", Value = subtract }; Outputs.Add(Output); } } }