-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathSumNodeViewModel.cs
50 lines (43 loc) · 1.49 KB
/
SumNodeViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Reactive.Linq;
using DynamicData;
using NodeNetwork.Toolkit.ValueNode;
using NodeNetwork.ViewModels;
using NodeNetwork.Views;
using ReactiveUI;
namespace ExampleCalculatorApp.ViewModels.Nodes
{
public class SumNodeViewModel : NodeViewModel
{
static SumNodeViewModel()
{
Splat.Locator.CurrentMutable.Register(() => new NodeView(), typeof(IViewFor<SumNodeViewModel>));
}
public ValueNodeInputViewModel<int?> Input1 { get; }
public ValueNodeInputViewModel<int?> Input2 { get; }
public ValueNodeOutputViewModel<int?> Output { get; }
public SumNodeViewModel()
{
Name = "Sum";
Input1 = new ValueNodeInputViewModel<int?>
{
Name = "A",
Editor = new IntegerValueEditorViewModel()
};
EditableInputs().Add(Input1);
Input2 = new ValueNodeInputViewModel<int?>
{
Name = "B",
Editor = new IntegerValueEditorViewModel()
};
EditableInputs().Add(Input2);
var sum = 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<int?>
{
Name = "A + B",
Value = sum
};
EditableOutputs().Add(Output);
}
}
}