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
executable file
·430 lines (378 loc) · 15.9 KB
/
Interfaces.cs
File metadata and controls
executable file
·430 lines (378 loc) · 15.9 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Reactive;
using System.Windows.Input;
using Splat;
namespace ReactiveUI
{
/// <summary>
/// IObservedChange is a generic interface that is returned from WhenAny()
/// Note that it is used for both Changing (i.e.'before change')
/// and Changed Observables.
/// </summary>
public interface IObservedChange<out TSender, out TValue>
{
/// <summary>
/// The object that has raised the change.
/// </summary>
TSender Sender { get; }
/// <summary>
/// The expression of the member that has changed on Sender.
/// </summary>
Expression Expression { 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 GetValue() extension method.
/// </summary>
TValue Value { get; }
}
/// <summary>
/// A data-only version of IObservedChange
/// </summary>
public class ObservedChange<TSender, TValue> : IObservedChange<TSender, TValue>
{
/// <summary>
/// Initializes a new instance of the <see cref="ObservedChange{TSender, TValue}"/> class.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="expression">Expression describing the member.</param>
/// <param name="value">The value.</param>
public ObservedChange(TSender sender, Expression expression, TValue value = default(TValue))
{
this.Sender = sender;
this.Expression = expression;
this.Value = value;
}
/// <summary>
///
/// </summary>
public TSender Sender { get; private set; }
/// <summary>
///
/// </summary>
public Expression Expression { get; private set; }
/// <summary>
///
/// </summary>
public TValue Value { get; private 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>
/// IReactivePropertyChangedEventArgs is a generic interface that
/// is used to wrap the NotifyPropertyChangedEventArgs and gives
/// information about changed properties. It includes also
/// the sender of the notification.
/// Note that it is used for both Changing (i.e.'before change')
/// and Changed Observables.
/// </summary>
public interface IReactivePropertyChangedEventArgs<out TSender>
{
/// <summary>
/// The name of the property that has changed on Sender.
/// </summary>
string PropertyName { get; }
/// <summary>
/// The object that has raised the change.
/// </summary>
TSender Sender { get; }
}
/// <summary>
///
/// </summary>
/// <typeparam name="TSender"></typeparam>
public class ReactivePropertyChangingEventArgs<TSender> : PropertyChangingEventArgs, IReactivePropertyChangedEventArgs<TSender>
{
/// <summary>
/// Initializes a new instance of the <see cref="ReactivePropertyChangingEventArgs{TSender}"/> class.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="propertyName">Name of the property.</param>
public ReactivePropertyChangingEventArgs(TSender sender, string propertyName)
: base(propertyName)
{
this.Sender = sender;
}
/// <summary>
///
/// </summary>
public TSender Sender { get; private set; }
}
/// <summary>
///
/// </summary>
/// <typeparam name="TSender"></typeparam>
public class ReactivePropertyChangedEventArgs<TSender> : PropertyChangedEventArgs, IReactivePropertyChangedEventArgs<TSender>
{
/// <summary>
/// Initializes a new instance of the <see cref="ReactivePropertyChangedEventArgs{TSender}"/> class.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="propertyName">Name of the property.</param>
public ReactivePropertyChangedEventArgs(TSender sender, string propertyName)
: base(propertyName)
{
this.Sender = sender;
}
/// <summary>
///
/// </summary>
public TSender Sender { get; private set; }
}
/// <summary>
/// IReactiveNotifyPropertyChanged represents an extended version of
/// INotifyPropertyChanged that also exposes typed Observables.
/// </summary>
public interface IReactiveNotifyPropertyChanged<out TSender>
{
/// <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<IReactivePropertyChangedEventArgs<TSender>> 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<IReactivePropertyChangedEventArgs<TSender>> 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>
/// IReactiveNotifyCollectionItemChanged provides notifications for collection item updates, ie when an object in
/// a collection changes.
/// </summary>
public interface IReactiveNotifyCollectionItemChanged<out TSender>
{
/// <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<IReactivePropertyChangedEventArgs<TSender>> 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<IReactivePropertyChangedEventArgs<TSender>> 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>
/// IReactiveNotifyCollectionChanged of T provides notifications when the contents
/// of collection are changed (items are added/removed/moved).
/// </summary>
public interface IReactiveNotifyCollectionChanged<out T>
{
/// <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<T> ItemsAdded { get; }
/// <summary>
/// Fires before an item is going to be added to the collection.
/// </summary>
IObservable<T> BeforeItemsAdded { get; }
/// <summary>
/// Fires once an item has been removed from a collection, providing the
/// item that was removed.
/// </summary>
IObservable<T> ItemsRemoved { get; }
/// <summary>
/// Fires before an item will be removed from a collection, providing
/// the item that will be removed.
/// </summary>
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>
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>
IObservable<IMoveInfo<T>> 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; }
IObservable<bool> IsEmptyChanged { 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();
}
/// IReactiveCollection of T represents a 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".
public interface IReactiveCollection<out T> : IReactiveNotifyCollectionChanged<T>, IReactiveNotifyCollectionItemChanged<T>, IEnumerable<T>, INotifyCollectionChanged, INotifyCollectionChanging, IReactiveObject
{
/// <summary>
///
/// </summary>
void Reset();
}
/// <summary>
/// IReadOnlyReactiveCollection of T 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>
/// IReadOnlyReactiveList of T 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>
{
bool IsEmpty { get; }
}
/// <summary>
/// IReactiveDerivedList represents 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<out T> : IReadOnlyReactiveList<T>, IDisposable
{
}
/// <summary>
/// IReactiveList of T 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>
{
bool IsEmpty { get; }
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);
}
/// <summary>
/// Implement this interface for ViewModels that can be navigated to.
/// </summary>
public interface IRoutableViewModel : IReactiveObject
{
/// <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; }
}
/// <summary>
/// Implementing this interface on a ViewModel indicates that the ViewModel
/// is interested in Activation events. Instantiate the Activator, then call
/// WhenActivated on your class to register what you want to happen when
/// the View is activated. See the documentation for ViewModelActivator to
/// read more about Activation.
/// </summary>
public interface ISupportsActivation
{
ViewModelActivator Activator { get; }
}
/// <summary>
/// This Interface is used by the framework to explicitly provide activation
/// events. Usually you can ignore this unless you are porting RxUI to a new
/// UI Toolkit.
/// </summary>
public interface ICanActivate
{
IObservable<Unit> Activated { get; }
IObservable<Unit> Deactivated { get; }
}
interface ICanForceManualActivation
{
void Activate(bool activate);
}
}
// vim: tw=120 ts=4 sw=4 et :