forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterfaces.cs
More file actions
480 lines (420 loc) · 19.2 KB
/
Interfaces.cs
File metadata and controls
480 lines (420 loc) · 19.2 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Reactive;
using System.Windows.Input;
using Splat;
namespace ReactiveUI
{
/// <summary>
/// IObservedChange is a generic interface that replaces the non-generic
/// PropertyChangedEventArgs. Note that it is used for both Changing (i.e.
/// 'before change') and Changed Observables. In the future, this interface
/// will be Covariant which will allow simpler casting between specific and
/// generic changes.
/// </summary>
public interface IObservedChange<out TSender, out TValue>
{
/// <summary>
/// The object that has raised the change.
/// </summary>
TSender Sender { get; }
/// <summary>
/// The name of the property that has changed on Sender.
/// </summary>
string PropertyName { get; }
/// <summary>
/// The value of the property that has changed. IMPORTANT NOTE: This
/// property is often not set for performance reasons, unless you have
/// explicitly requested an Observable for a property via a method such
/// as ObservableForProperty. To retrieve the value for the property,
/// use the Value() extension method.
/// </summary>
TValue Value { get; }
}
/// <summary>
/// A data-only version of IObservedChange
/// </summary>
public class ObservedChange<TSender, TValue> : IObservedChange<TSender, TValue>
{
public TSender Sender { get; set; }
public string PropertyName { get; set; }
public TValue Value { get; set; }
}
/// <summary>
/// This interface is implemented by RxUI objects which are given
/// IObservables as input - when the input IObservables OnError, instead of
/// disabling the RxUI object, we catch the IObservable and pipe it into
/// this property.
///
/// Normally this IObservable is implemented with a ScheduledSubject whose
/// default Observer is RxApp.DefaultExceptionHandler - this means, that if
/// you aren't listening to ThrownExceptions and one appears, the exception
/// will appear on the UI thread and crash the application.
/// </summary>
public interface IHandleObservableErrors
{
/// <summary>
/// Fires whenever an exception would normally terminate ReactiveUI
/// internal state.
/// </summary>
IObservable<Exception> ThrownExceptions { get; }
}
/// <summary>
/// IReactiveCommand represents an ICommand which also notifies when it is
/// executed (i.e. when Execute is called) via IObservable. Conceptually,
/// this represents an Event, so as a result this IObservable should never
/// OnComplete or OnError.
///
/// In previous versions of ReactiveUI, this interface was split into two
/// separate interfaces, one to handle async methods and one for "standard"
/// commands, but these have now been merged - every ReactiveCommand is now
/// a ReactiveAsyncCommand.
/// </summary>
public interface IReactiveCommand : IHandleObservableErrors, IObservable<object>, ICommand, IDisposable, IEnableLogger
{
/// <summary>
/// Registers an asynchronous method to be called whenever the command
/// is Executed. This method returns an IObservable representing the
/// asynchronous operation, and is allowed to OnError / should OnComplete.
/// </summary>
/// <returns>A filtered version of the Observable which is marshaled
/// to the UI thread. This Observable should only report successes and
/// instead send OnError messages to the ThrownExceptions property.
/// </returns>
/// <param name="asyncBlock">The asynchronous method to call.</param>
IObservable<T> RegisterAsync<T>(Func<object, IObservable<T>> asyncBlock);
/// <summary>
/// Gets a value indicating whether this instance can execute observable.
/// </summary>
/// <value><c>true</c> if this instance can execute observable; otherwise, <c>false</c>.</value>
IObservable<bool> CanExecuteObservable { get; }
/// <summary>
/// Gets a value indicating whether this instance is executing. This
/// Observable is guaranteed to always return a value immediately (i.e.
/// it is backed by a BehaviorSubject), meaning it is safe to determine
/// the current state of the command via IsExecuting.First()
/// </summary>
/// <value><c>true</c> if this instance is executing; otherwise, <c>false</c>.</value>
IObservable<bool> IsExecuting { get; }
/// <summary>
/// Gets a value indicating whether this
/// <see cref="ReactiveUI.IReactiveCommand"/> allows concurrent
/// execution. If false, the CanExecute of the command will be disabled
/// while async operations are currently in-flight.
/// </summary>
/// <value><c>true</c> if allows concurrent execution; otherwise, <c>false</c>.</value>
bool AllowsConcurrentExecution { get; }
}
/// <summary>
/// IReactiveNotifyPropertyChanged represents an extended version of
/// INotifyPropertyChanged that also exposes Observables.
/// </summary>
public interface IReactiveNotifyPropertyChanged : INotifyPropertyChanged, INotifyPropertyChanging, IEnableLogger
{
/// <summary>
/// Represents an Observable that fires *before* a property is about to
/// be changed. Note that this should not fire duplicate change notifications if a
/// property is set to the same value multiple times.
/// </summary>
IObservable<IObservedChange<object, object>> Changing { get; }
/// <summary>
/// Represents an Observable that fires *after* a property has changed.
/// Note that this should not fire duplicate change notifications if a
/// property is set to the same value multiple times.
/// </summary>
IObservable<IObservedChange<object, object>> Changed { get; }
/// <summary>
/// When this method is called, an object will not fire change
/// notifications (neither traditional nor Observable notifications)
/// until the return value is disposed.
/// </summary>
/// <returns>An object that, when disposed, reenables change
/// notifications.</returns>
IDisposable SuppressChangeNotifications();
}
/// <summary>
/// IReactiveNotifyPropertyChanged of TSender is a helper interface that adds
/// typed versions of Changing and Changed.
/// </summary>
public interface IReactiveNotifyPropertyChanged<out TSender> : IReactiveNotifyPropertyChanged
{
new IObservable<IObservedChange<TSender, object>> Changing { get; }
new IObservable<IObservedChange<TSender, object>> Changed { get; }
}
/// <summary>
/// IReactiveNotifyCollectionItemChanged provides notifications for collection item updates, ie when an object in
/// a collection changes.
/// </summary>
public interface IReactiveNotifyCollectionItemChanged
{
/// <summary>
/// Provides Item Changing notifications for any item in collection that
/// implements IReactiveNotifyPropertyChanged. This is only enabled when
/// ChangeTrackingEnabled is set to True.
/// </summary>
IObservable<IObservedChange<object, object>> ItemChanging { get; }
/// <summary>
/// Provides Item Changed notifications for any item in collection that
/// implements IReactiveNotifyPropertyChanged. This is only enabled when
/// ChangeTrackingEnabled is set to True.
/// </summary>
IObservable<IObservedChange<object, object>> ItemChanged { get; }
/// <summary>
/// Enables the ItemChanging and ItemChanged properties; when this is
/// enabled, whenever a property on any object implementing
/// IReactiveNotifyPropertyChanged changes, the change will be
/// rebroadcast through ItemChanging/ItemChanged.
/// </summary>
bool ChangeTrackingEnabled { get; set; }
}
/// <summary>
/// IReactiveNotifyCollectionItemChanged of T is the typed version of IReactiveNotifyCollectionItemChanged and
/// adds type-specified versions of Observables
/// </summary>
public interface IReactiveNotifyCollectionItemChanged<out T> : IReactiveNotifyCollectionItemChanged
{
/// <summary>
/// Provides Item Changing notifications for any item in collection that
/// implements IReactiveNotifyPropertyChanged. This is only enabled when
/// ChangeTrackingEnabled is set to True.
/// </summary>
new IObservable<IObservedChange<T, object>> ItemChanging { get; }
/// <summary>
/// Provides Item Changed notifications for any item in collection that
/// implements IReactiveNotifyPropertyChanged. This is only enabled when
/// ChangeTrackingEnabled is set to True.
/// </summary>
new IObservable<IObservedChange<T, object>> ItemChanged { get; }
}
/// <summary>
/// IReactiveCollection provides notifications when the contents
/// of collection are changed (items are added/removed/moved).
/// </summary>
public interface IReactiveNotifyCollectionChanged : INotifyCollectionChanged
{
/// <summary>
/// Fires when items are added to the collection, once per item added.
/// Functions that add multiple items such AddRange should fire this
/// multiple times. The object provided is the item that was added.
/// </summary>
IObservable<object> ItemsAdded { get; }
/// <summary>
/// Fires before an item is going to be added to the collection.
/// </summary>
IObservable<object> BeforeItemsAdded { get; }
/// <summary>
/// Fires once an item has been removed from a collection, providing the
/// item that was removed.
/// </summary>
IObservable<object> ItemsRemoved { get; }
/// <summary>
/// Fires before an item will be removed from a collection, providing
/// the item that will be removed.
/// </summary>
IObservable<object> BeforeItemsRemoved { get; }
/// <summary>
/// Fires before an items moves from one position in the collection to
/// another, providing the item(s) to be moved as well as source and destination
/// indices.
/// </summary>
IObservable<IMoveInfo<object>> BeforeItemsMoved { get; }
/// <summary>
/// Fires once one or more items moves from one position in the collection to
/// another, providing the item(s) that was moved as well as source and destination
/// indices.
/// </summary>
IObservable<IMoveInfo<object>> ItemsMoved { get; }
/// <summary>
/// This Observable is equivalent to the NotifyCollectionChanged event,
/// but fires before the collection is changed
/// </summary>
IObservable<NotifyCollectionChangedEventArgs> Changing { get; }
/// <summary>
/// This Observable is equivalent to the NotifyCollectionChanged event,
/// and fires after the collection is changed
/// </summary>
IObservable<NotifyCollectionChangedEventArgs> Changed { get; }
/// <summary>
/// Fires when the collection count changes, regardless of reason
/// </summary>
IObservable<int> CountChanging { get; }
/// <summary>
/// Fires when the collection count changes, regardless of reason
/// </summary>
IObservable<int> CountChanged { get; }
/// <summary>
/// This Observable is fired when a ShouldReset fires on the collection. This
/// means that you should forget your previous knowledge of the state
/// of the collection and reread it.
///
/// This does *not* mean Clear, and if you interpret it as such, you are
/// Doing It Wrong.
/// </summary>
IObservable<Unit> ShouldReset { get; }
IDisposable SuppressChangeNotifications();
}
/// <summary>
/// IReactiveNotifyCollectionChanged of T is the typed version of IReactiveNotifyCollectionChanged and
/// adds type-specified versions of Observables
/// </summary>
public interface IReactiveNotifyCollectionChanged<out T> : IReactiveNotifyCollectionChanged
{
/// <summary>
/// Fires when items are added to the collection, once per item added.
/// Functions that add multiple items such AddRange should fire this
/// multiple times. The object provided is the item that was added.
/// </summary>
new IObservable<T> ItemsAdded { get; }
/// <summary>
/// Fires before an item is going to be added to the collection.
/// </summary>
new IObservable<T> BeforeItemsAdded { get; }
/// <summary>
/// Fires once an item has been removed from a collection, providing the
/// item that was removed.
/// </summary>
new IObservable<T> ItemsRemoved { get; }
/// <summary>
/// Fires before an item will be removed from a collection, providing
/// the item that will be removed.
/// </summary>
new IObservable<T> BeforeItemsRemoved { get; }
/// <summary>
/// Fires before an items moves from one position in the collection to
/// another, providing the item(s) to be moved as well as source and destination
/// indices.
/// </summary>
new IObservable<IMoveInfo<T>> BeforeItemsMoved { get; }
/// <summary>
/// Fires once one or more items moves from one position in the collection to
/// another, providing the item(s) that was moved as well as source and destination
/// indices.
/// </summary>
new IObservable<IMoveInfo<T>> ItemsMoved { get; }
}
/// <summary>
/// IReactiveCollection of T is the typed version of IReactiveCollection and
/// adds type-specified versions of Observables
/// </summary>
public interface IReactiveCollection<out T> : IReactiveNotifyCollectionChanged<T>, IReactiveNotifyCollectionItemChanged<T>, IEnumerable<T>, INotifyPropertyChanging, INotifyPropertyChanged, IEnableLogger
{
void Reset();
}
/// <summary>
/// IReadOnlyReactiveCollection represents a read-only collection that can notify when its
/// contents are changed (either items are added/removed, or the object
/// itself changes).
///
/// It is important to implement the Changing/Changed from
/// IReactiveNotifyPropertyChanged semantically as "Fire when *anything* in
/// the collection or any of its items have changed, in any way".
/// </summary>
public interface IReadOnlyReactiveCollection<out T> : IReadOnlyCollection<T>, IReactiveCollection<T>
{
}
/// <summary>
/// IReactiveList represents a read-only list that can notify when its
/// contents are changed (either items are added/removed, or the object
/// itself changes).
///
/// It is important to implement the Changing/Changed from
/// IReactiveNotifyPropertyChanged semantically as "Fire when *anything* in
/// the collection or any of its items have changed, in any way".
/// </summary>
public interface IReadOnlyReactiveList<out T> : IReadOnlyReactiveCollection<T>, IReadOnlyList<T>
{
}
/// <summary>
/// IReactiveDerivedList repreents a collection whose contents will "follow" another
/// collection; this method is useful for creating ViewModel collections
/// that are automatically updated when the respective Model collection is updated.
/// </summary>
public interface IReactiveDerivedList<T> : IReadOnlyReactiveList<T>, IDisposable
{
}
/// <summary>
/// IReactiveList represents a list that can notify when its
/// contents are changed (either items are added/removed, or the object
/// itself changes).
///
/// It is important to implement the Changing/Changed from
/// IReactiveNotifyPropertyChanged semantically as "Fire when *anything* in
/// the collection or any of its items have changed, in any way".
/// </summary>
public interface IReactiveList<T> : IReactiveCollection<T>, IList<T>
{
void AddRange(IEnumerable<T> collection);
void InsertRange(int index, IEnumerable<T> collection);
void RemoveAll(IEnumerable<T> items);
void RemoveRange(int index, int count);
void Sort(IComparer<T> comparer = null);
void Sort(Comparison<T> comparison);
void Sort(int index, int count, IComparer<T> comparer);
}
// NB: This is just a name we can bolt extension methods to
public interface INavigateCommand : IReactiveCommand { }
public interface IRoutingState : IReactiveNotifyPropertyChanged
{
/// <summary>
/// Represents the current navigation stack, the last element in the
/// collection being the currently visible ViewModel.
/// </summary>
ReactiveList<IRoutableViewModel> NavigationStack { get; }
/// <summary>
/// Navigates back to the previous element in the stack.
/// </summary>
IReactiveCommand NavigateBack { get; }
/// <summary>
/// Navigates to the a new element in the stack - the Execute parameter
/// must be a ViewModel that implements IRoutableViewModel.
/// </summary>
INavigateCommand Navigate { get; }
/// <summary>
/// Navigates to a new element and resets the navigation stack (i.e. the
/// new ViewModel will now be the only element in the stack) - the
/// Execute parameter must be a ViewModel that implements
/// IRoutableViewModel.
/// </summary>
INavigateCommand NavigateAndReset { get; }
IObservable<IRoutableViewModel> CurrentViewModel { get; }
}
/// <summary>
/// Implement this interface for ViewModels that can be navigated to.
/// </summary>
public interface IRoutableViewModel : IReactiveNotifyPropertyChanged
{
/// <summary>
/// A string token representing the current ViewModel, such as 'login' or 'user'
/// </summary>
string UrlPathSegment { get; }
/// <summary>
/// The IScreen that this ViewModel is currently being shown in. This
/// is usually passed into the ViewModel in the Constructor and saved
/// as a ReadOnly Property.
/// </summary>
IScreen HostScreen { get; }
}
public interface ISupportsActivation
{
ViewModelActivator Activator { get; }
}
public interface ICanActivate
{
IObservable<Unit> Activated { get; }
IObservable<Unit> Deactivated { get; }
}
/// <summary>
/// Allows an additional string to make view resolution more specific than just a type.
/// </summary>
public class ViewContractAttribute : Attribute
{
/// <summary>
/// A unique string that will be used along with the type to resolve a View
/// </summary>
public string Contract { get; set; }
}
}
// vim: tw=120 ts=4 sw=4 et :