-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathDivisionNodeViewModel.cs
51 lines (44 loc) · 1.57 KB
/
DivisionNodeViewModel.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
51
using System.Reactive;
using System.Reactive.Linq;
using DynamicData;
using NodeNetwork.Toolkit.ValueNode;
using NodeNetwork.ViewModels;
using NodeNetwork.Views;
using ReactiveUI;
namespace ExampleCalculatorApp.ViewModels.Nodes
{
public class DivisionNodeViewModel : NodeViewModel
{
static DivisionNodeViewModel()
{
Splat.Locator.CurrentMutable.Register(() => new NodeView(), typeof(IViewFor<DivisionNodeViewModel>));
}
public ValueNodeInputViewModel<int?> Input1 { get; }
public ValueNodeInputViewModel<int?> Input2 { get; }
public ValueNodeOutputViewModel<int?> Output { get; }
public DivisionNodeViewModel()
{
Name = "Divide";
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 divide = this.WhenAnyValue(vm => vm.Input1.Value, vm => vm.Input2.Value)
.Select(_ => Input1.Value != null && Input2.Value != null && Input2.Value != 0 ? Input1.Value / Input2.Value : null);
Output = new ValueNodeOutputViewModel<int?>
{
Name = "A / B",
Value = divide
};
EditableOutputs().Add(Output);
}
}
}