6
6
using System ;
7
7
using System . Buffers ;
8
8
using System . Collections . Generic ;
9
- using System . Diagnostics . CodeAnalysis ;
10
9
using System . Linq ;
11
10
using System . Reactive . Concurrency ;
12
11
using System . Reactive . Disposables ;
@@ -31,15 +30,16 @@ namespace ReactiveUI.Validation.Contexts;
31
30
/// </remarks>
32
31
public class ValidationContext : ReactiveObject , IValidationContext
33
32
{
33
+ private readonly CompositeDisposable _disposables = [ ] ;
34
+
34
35
private readonly ReplaySubject < IValidationState > _validationStatusChange = new ( 1 ) ;
35
36
private readonly ReplaySubject < bool > _validSubject = new ( 1 ) ;
36
37
37
- private readonly IConnectableObservable < bool > _validationConnectable ;
38
+ private readonly IObservable < bool > _validationObservable ;
38
39
private readonly ObservableAsPropertyHelper < IValidationText > _validationText ;
39
40
private readonly ObservableAsPropertyHelper < bool > _isValid ;
40
41
41
- private readonly CompositeDisposable _disposables = [ ] ;
42
- private SourceList < IValidationComponent > _validationSource = new ( ) ;
42
+ private readonly SourceList < IValidationComponent > _validationSource = new ( ) ;
43
43
private bool _isActive ;
44
44
45
45
/// <summary>
@@ -52,15 +52,14 @@ public ValidationContext(IScheduler? scheduler = null)
52
52
var changeSets = _validationSource . Connect ( ) . ObserveOn ( scheduler ) ;
53
53
Validations = changeSets . AsObservableList ( ) ;
54
54
55
- _validationConnectable = changeSets
55
+ _validationObservable = changeSets
56
56
. StartWithEmpty ( )
57
57
. AutoRefreshOnObservable ( x => x . ValidationStatusChange )
58
58
. QueryWhenChanged ( static x =>
59
59
{
60
- using ReadOnlyCollectionPooled < IValidationComponent > validationComponents = new ( x ) ;
60
+ using ReadOnlyDisposableCollection < IValidationComponent > validationComponents = new ( x ) ;
61
61
return validationComponents . Count is 0 || validationComponents . All ( v => v . IsValid ) ;
62
- } )
63
- . Multicast ( _validSubject ) ;
62
+ } ) ;
64
63
65
64
_isValid = _validSubject
66
65
. StartWith ( true )
@@ -95,7 +94,7 @@ public IObservable<bool> Valid
95
94
/// <summary>
96
95
/// Gets get the list of validations.
97
96
/// </summary>
98
- public IObservableList < IValidationComponent > Validations { get ; private set ; }
97
+ public IObservableList < IValidationComponent > Validations { get ; }
99
98
100
99
/// <inheritdoc/>
101
100
public bool IsValid
@@ -162,10 +161,7 @@ public IValidationText Text
162
161
/// <inheritdoc/>
163
162
public void Dispose ( )
164
163
{
165
- // Dispose of unmanaged resources.
166
164
Dispose ( true ) ;
167
-
168
- // Suppress finalization.
169
165
GC . SuppressFinalize ( this ) ;
170
166
}
171
167
@@ -183,11 +179,8 @@ protected virtual void Dispose(bool disposing)
183
179
_validationStatusChange . Dispose ( ) ;
184
180
_validSubject . Dispose ( ) ;
185
181
_validationSource . Clear ( ) ;
186
- Validations . Dispose ( ) ;
187
182
_validationSource . Dispose ( ) ;
188
-
189
- Validations = null ! ;
190
- _validationSource = null ! ;
183
+ Validations . Dispose ( ) ;
191
184
}
192
185
}
193
186
@@ -199,7 +192,7 @@ private void Activate()
199
192
}
200
193
201
194
_isActive = true ;
202
- _disposables . Add ( _validationConnectable . Connect ( ) ) ;
195
+ _disposables . Add ( _validationObservable . Subscribe ( _validSubject ) ) ;
203
196
}
204
197
205
198
/// <summary>
0 commit comments