Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c06c90a

Browse files
authoredFeb 12, 2023
Merge pull request #411 from runceel/main
Release v9.0.0
2 parents 5e8e25f + e1a0c73 commit c06c90a

File tree

79 files changed

+5441
-702
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+5441
-702
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations;
3+
using System.Reactive.Subjects;
4+
using BenchmarkDotNet.Attributes;
5+
using Reactive.Bindings;
6+
using Reactive.Bindings.Extensions;
7+
8+
namespace ReactivePropertyBenchmark;
9+
10+
public partial class BasicUsages
11+
{
12+
[Benchmark]
13+
public ReactiveCommand CreateReactiveCommand() => new ReactiveCommand();
14+
15+
[Benchmark]
16+
public ReactiveCommandSlim CreateReactiveCommandSlim() => new ReactiveCommandSlim();
17+
18+
19+
20+
[Benchmark]
21+
public ReactiveCommand BasicUsecaseForReactiveCommand()
22+
{
23+
var subject = new Subject<bool>();
24+
var cmd = subject.ToReactiveCommand();
25+
cmd.Subscribe(x => { });
26+
cmd.Execute();
27+
subject.OnNext(true);
28+
cmd.Execute();
29+
return cmd;
30+
}
31+
32+
[Benchmark]
33+
public ReactiveCommandSlim BasicUsecaseForReactiveCommandSlim()
34+
{
35+
var subject = new Subject<bool>();
36+
var cmd = subject.ToReactiveCommandSlim();
37+
cmd.Subscribe(x => { });
38+
cmd.Execute();
39+
subject.OnNext(true);
40+
cmd.Execute();
41+
return cmd;
42+
}
43+
44+
[Benchmark]
45+
public ReactiveProperty<string> ReactivePropertyValidation()
46+
{
47+
var rp = new ReactiveProperty<string>("")
48+
.SetValidateNotifyError(x => string.IsNullOrEmpty(x) ? "invalid" : null);
49+
rp.Value = "xxx"; // valid
50+
rp.Value = ""; // invalid
51+
return rp;
52+
}
53+
54+
[Benchmark]
55+
public ValidatableReactiveProperty<string> ValidatableReactivePropertyValidation()
56+
{
57+
var rp = new ValidatableReactiveProperty<string>(
58+
"",
59+
x => string.IsNullOrEmpty(x) ? "invalid" : null);
60+
rp.Value = "xxx"; // valid
61+
rp.Value = ""; // invalid
62+
return rp;
63+
}
64+
65+
[Benchmark]
66+
public ReactivePropertyVM ReactivePropertyValidationFromPoco()
67+
{
68+
var vm = new ReactivePropertyVM();
69+
vm.Name.Value = "valid";
70+
vm.Name.Value = "";
71+
vm.Dispose();
72+
return vm;
73+
}
74+
75+
[Benchmark]
76+
public ValidatableReactivePropertyVM ValidatableReactivePropertyValidationFromPoco()
77+
{
78+
var vm = new ValidatableReactivePropertyVM();
79+
vm.Name.Value = "valid";
80+
vm.Name.Value = "";
81+
vm.Dispose();
82+
return vm;
83+
}
84+
85+
[Benchmark]
86+
public IObservable<string> ObservePropertyLegacy()
87+
{
88+
var p = new Person();
89+
return p.ObservePropertyLegacy(x => x.Name);
90+
}
91+
92+
[Benchmark]
93+
public ReactivePropertySlim<string> ToReactivePropertyAsSynchronizedSlim()
94+
{
95+
var p = new Person();
96+
return p.ToReactivePropertySlimAsSynchronized(x => x.Name);
97+
}
98+
}
99+
100+
public class ReactivePropertyVM : IDisposable
101+
{
102+
private Person _model = new();
103+
104+
[Required]
105+
public ReactiveProperty<string> Name { get; }
106+
107+
public ReactivePropertyVM()
108+
{
109+
Name = _model.ToReactivePropertyAsSynchronized(x => x.Name,
110+
ignoreValidationErrorValue: true)
111+
.SetValidateAttribute(() => Name);
112+
}
113+
114+
public void Dispose()
115+
{
116+
Name.Dispose();
117+
}
118+
}
119+
120+
public class ValidatableReactivePropertyVM : IDisposable
121+
{
122+
private Person _model = new();
123+
124+
[Required]
125+
public ValidatableReactiveProperty<string> Name { get; }
126+
127+
public ValidatableReactivePropertyVM()
128+
{
129+
Name = _model.ToReactivePropertySlimAsSynchronized(x => x.Name)
130+
.ToValidatableReactiveProperty(
131+
() => Name,
132+
disposeSource: true);
133+
}
134+
135+
public void Dispose()
136+
{
137+
Name.Dispose();
138+
}
139+
}

‎Benchmark/Benchmark.V6/BasicUsages.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4+
using System.Reactive.Subjects;
45
using System.Runtime.CompilerServices;
56
using System.Text;
67
using BenchmarkDotNet.Attributes;
@@ -9,7 +10,7 @@
910

1011
namespace ReactivePropertyBenchmark
1112
{
12-
public class BasicUsages
13+
public partial class BasicUsages
1314
{
1415
[Benchmark]
1516
public ReactiveProperty<string> CreateReactivePropertyInstance() => new ReactiveProperty<string>();

0 commit comments

Comments
 (0)
Please sign in to comment.