|
4 | 4 |
|
5 | 5 | namespace StrawberryShake.Razor
|
6 | 6 | {
|
| 7 | + /// <summary> |
| 8 | + /// A data component can be used to remove boiler plate from using reactive data operations. |
| 9 | + /// </summary> |
| 10 | + /// <typeparam name="TClientOrOperation"> |
| 11 | + /// The client or operation this component shall interact with. |
| 12 | + /// </typeparam> |
7 | 13 | public abstract class DataComponent<TClientOrOperation>
|
8 | 14 | : ComponentBase
|
9 | 15 | , IDisposable
|
10 | 16 | {
|
11 | 17 | private readonly List<IDisposable> _subscriptions = new();
|
12 | 18 | private bool _disposed;
|
13 | 19 |
|
| 20 | + /// <summary> |
| 21 | + /// Gets the client or operation. |
| 22 | + /// </summary> |
14 | 23 | [Inject]
|
15 | 24 | protected internal TClientOrOperation ClientOrOperation { get; internal set; } = default!;
|
16 | 25 |
|
17 |
| - public void Subscribe(Func<TClientOrOperation, IDisposable> subscribe) |
| 26 | + /// <summary> |
| 27 | + /// Gets the data client. |
| 28 | + /// </summary> |
| 29 | + protected TClientOrOperation Client => ClientOrOperation; |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Gets the data operation. |
| 33 | + /// </summary> |
| 34 | + protected TClientOrOperation Operation => ClientOrOperation; |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Registers a data subscription with the component. |
| 38 | + /// The component will dispose any registered subscription when it is disposed. |
| 39 | + /// </summary> |
| 40 | + /// <param name="subscribe"> |
| 41 | + /// The subscribe delegate creating a data subscription. |
| 42 | + /// </param> |
| 43 | + /// <exception cref="ArgumentNullException"> |
| 44 | + /// <paramref name="subscribe"/> is <c>null</c>. |
| 45 | + /// </exception> |
| 46 | + public void Register(Func<TClientOrOperation, IDisposable> subscribe) |
18 | 47 | {
|
| 48 | + if (subscribe is null) |
| 49 | + { |
| 50 | + throw new ArgumentNullException(nameof(subscribe)); |
| 51 | + } |
| 52 | + |
19 | 53 | _subscriptions.Add(subscribe(ClientOrOperation));
|
20 | 54 | }
|
21 | 55 |
|
| 56 | + /// <summary> |
| 57 | + /// Registers a data subscription with the component. |
| 58 | + /// The component will dispose any registered subscription when it is disposed. |
| 59 | + /// </summary> |
| 60 | + /// <param name="subscribe"> |
| 61 | + /// The subscribe delegate creating a data subscription. |
| 62 | + /// </param> |
| 63 | + /// <exception cref="ArgumentNullException"> |
| 64 | + /// <paramref name="subscribe"/> is <c>null</c>. |
| 65 | + /// </exception> |
| 66 | + [Obsolete("Use Register(Func<TClientOrOperation, IDisposable> subscribe)")] |
| 67 | + public void Subscribe(Func<TClientOrOperation, IDisposable> subscribe) => |
| 68 | + Register(subscribe); |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Performs application-defined tasks associated with freeing, |
| 72 | + /// releasing, or resetting unmanaged resources. |
| 73 | + /// </summary> |
22 | 74 | public void Dispose()
|
23 | 75 | {
|
24 | 76 | Dispose(true);
|
25 | 77 | GC.SuppressFinalize(this);
|
26 | 78 | }
|
27 | 79 |
|
| 80 | + /// <summary> |
| 81 | + /// Performs application-defined tasks associated with freeing, |
| 82 | + /// releasing, or resetting unmanaged resources. |
| 83 | + /// </summary> |
28 | 84 | protected void Dispose(bool disposing)
|
29 | 85 | {
|
30 | 86 | if (!_disposed)
|
|
0 commit comments