com.fofx.observething 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +2 -0
  2. package/README.md.meta +7 -0
  3. package/Runtime/CollectionIdProvider.cs +72 -0
  4. package/Runtime/CollectionIdProvider.cs.meta +2 -0
  5. package/Runtime/IObservable.cs +66 -0
  6. package/Runtime/IObservable.cs.meta +2 -0
  7. package/Runtime/Implementations/Observable.cs +30 -0
  8. package/Runtime/Implementations/Observable.cs.meta +2 -0
  9. package/Runtime/Implementations/ObservableBase.cs +173 -0
  10. package/Runtime/Implementations/ObservableBase.cs.meta +2 -0
  11. package/Runtime/Implementations/ObservableCollection.cs +141 -0
  12. package/Runtime/Implementations/ObservableCollection.cs.meta +2 -0
  13. package/Runtime/Implementations/ObservableDictionary.cs +166 -0
  14. package/Runtime/Implementations/ObservableDictionary.cs.meta +2 -0
  15. package/Runtime/Implementations/ObservableList.cs +163 -0
  16. package/Runtime/Implementations/ObservableList.cs.meta +2 -0
  17. package/Runtime/Implementations/ObservableSet.cs +137 -0
  18. package/Runtime/Implementations/ObservableSet.cs.meta +2 -0
  19. package/Runtime/Implementations/ObservableValue.cs +59 -0
  20. package/Runtime/Implementations/ObservableValue.cs.meta +2 -0
  21. package/Runtime/Implementations.meta +8 -0
  22. package/Runtime/Observables/BatchObservable.cs +72 -0
  23. package/Runtime/Observables/BatchObservable.cs.meta +2 -0
  24. package/Runtime/Observables/CastObservable.cs +128 -0
  25. package/Runtime/Observables/CastObservable.cs.meta +2 -0
  26. package/Runtime/Observables/CombineObservable.cs +96 -0
  27. package/Runtime/Observables/CombineObservable.cs.meta +2 -0
  28. package/Runtime/Observables/CombineValueObservable.cs +319 -0
  29. package/Runtime/Observables/CombineValueObservable.cs.meta +2 -0
  30. package/Runtime/Observables/ConcatObservable.cs +75 -0
  31. package/Runtime/Observables/ConcatObservable.cs.meta +2 -0
  32. package/Runtime/Observables/ContainsObservable.cs +71 -0
  33. package/Runtime/Observables/ContainsObservable.cs.meta +2 -0
  34. package/Runtime/Observables/CountObservable.cs +29 -0
  35. package/Runtime/Observables/CountObservable.cs.meta +2 -0
  36. package/Runtime/Observables/DistinctObservable.cs +55 -0
  37. package/Runtime/Observables/DistinctObservable.cs.meta +2 -0
  38. package/Runtime/Observables/FirstObservable.cs +53 -0
  39. package/Runtime/Observables/FirstObservable.cs.meta +2 -0
  40. package/Runtime/Observables/IndexOfObservable.cs +83 -0
  41. package/Runtime/Observables/IndexOfObservable.cs.meta +2 -0
  42. package/Runtime/Observables/OperationStreamObservable.cs +194 -0
  43. package/Runtime/Observables/OperationStreamObservable.cs.meta +2 -0
  44. package/Runtime/Observables/OrderByObservable.cs +116 -0
  45. package/Runtime/Observables/OrderByObservable.cs.meta +2 -0
  46. package/Runtime/Observables/SelectCollectionObservable.cs +29 -0
  47. package/Runtime/Observables/SelectCollectionObservable.cs.meta +2 -0
  48. package/Runtime/Observables/SelectListObservable.cs +29 -0
  49. package/Runtime/Observables/SelectListObservable.cs.meta +2 -0
  50. package/Runtime/Observables/SelectManyObservable.cs +78 -0
  51. package/Runtime/Observables/SelectManyObservable.cs.meta +2 -0
  52. package/Runtime/Observables/SelectValueObservable.cs +28 -0
  53. package/Runtime/Observables/SelectValueObservable.cs.meta +2 -0
  54. package/Runtime/Observables/SkipWhileObservable.cs +32 -0
  55. package/Runtime/Observables/SkipWhileObservable.cs.meta +2 -0
  56. package/Runtime/Observables/ThenObservable.cs +209 -0
  57. package/Runtime/Observables/ThenObservable.cs.meta +2 -0
  58. package/Runtime/Observables/ToDictionaryObservable.cs +35 -0
  59. package/Runtime/Observables/ToDictionaryObservable.cs.meta +2 -0
  60. package/Runtime/Observables/TrackObservable.cs +74 -0
  61. package/Runtime/Observables/TrackObservable.cs.meta +2 -0
  62. package/Runtime/Observables/UnwrapCollectionObservable.cs +64 -0
  63. package/Runtime/Observables/UnwrapCollectionObservable.cs.meta +2 -0
  64. package/Runtime/Observables/UnwrapListObservable.cs +69 -0
  65. package/Runtime/Observables/UnwrapListObservable.cs.meta +2 -0
  66. package/Runtime/Observables/UnwrapValueObservable.cs +56 -0
  67. package/Runtime/Observables/UnwrapValueObservable.cs.meta +2 -0
  68. package/Runtime/Observables/WhereObservable.cs +85 -0
  69. package/Runtime/Observables/WhereObservable.cs.meta +2 -0
  70. package/Runtime/Observables/WithPreviousObservable.cs +36 -0
  71. package/Runtime/Observables/WithPreviousObservable.cs.meta +2 -0
  72. package/Runtime/Observables.cs +467 -0
  73. package/Runtime/Observables.cs.meta +2 -0
  74. package/Runtime/Observables.meta +8 -0
  75. package/Runtime/ObservationContext.cs +126 -0
  76. package/Runtime/ObservationContext.cs.meta +2 -0
  77. package/Runtime/Observers.cs +403 -0
  78. package/Runtime/Observers.cs.meta +2 -0
  79. package/Runtime/Operators/BatchOperator.cs +71 -0
  80. package/Runtime/Operators/BatchOperator.cs.meta +2 -0
  81. package/Runtime/Operators/CollectionOperator.cs +30 -0
  82. package/Runtime/Operators/CollectionOperator.cs.meta +2 -0
  83. package/Runtime/Operators/DictionaryOperator.cs +45 -0
  84. package/Runtime/Operators/DictionaryOperator.cs.meta +2 -0
  85. package/Runtime/Operators/IInitializationOperationsProvider.cs +10 -0
  86. package/Runtime/Operators/IInitializationOperationsProvider.cs.meta +2 -0
  87. package/Runtime/Operators/ListOperator.cs +44 -0
  88. package/Runtime/Operators/ListOperator.cs.meta +2 -0
  89. package/Runtime/Operators/ObservableOperator.cs +75 -0
  90. package/Runtime/Operators/ObservableOperator.cs.meta +2 -0
  91. package/Runtime/Operators/Operator.cs +65 -0
  92. package/Runtime/Operators/Operator.cs.meta +2 -0
  93. package/Runtime/Operators/SetOperator.cs +44 -0
  94. package/Runtime/Operators/SetOperator.cs.meta +2 -0
  95. package/Runtime/Operators/ValueOperator.cs +30 -0
  96. package/Runtime/Operators/ValueOperator.cs.meta +2 -0
  97. package/Runtime/Operators.meta +8 -0
  98. package/Runtime/PriorityQueue.cs +1096 -0
  99. package/Runtime/PriorityQueue.cs.meta +2 -0
  100. package/Runtime/com.fofx.observething.asmdef +14 -0
  101. package/Runtime/com.fofx.observething.asmdef.meta +7 -0
  102. package/Runtime.meta +8 -0
  103. package/Tests/CollectionObservableTests.cs +739 -0
  104. package/Tests/CollectionObservableTests.cs.meta +2 -0
  105. package/Tests/DictionaryObservableTests.cs +85 -0
  106. package/Tests/DictionaryObservableTests.cs.meta +2 -0
  107. package/Tests/ListObservableTests.cs +148 -0
  108. package/Tests/ListObservableTests.cs.meta +2 -0
  109. package/Tests/ObservationContextTests.cs +359 -0
  110. package/Tests/ObservationContextTests.cs.meta +2 -0
  111. package/Tests/ValueObservableTests.cs +322 -0
  112. package/Tests/ValueObservableTests.cs.meta +2 -0
  113. package/Tests/com.fofx.observething.tests.asmdef +24 -0
  114. package/Tests/com.fofx.observething.tests.asmdef.meta +7 -0
  115. package/Tests.meta +8 -0
  116. package/package.json +24 -0
  117. package/package.json.meta +7 -0
@@ -0,0 +1,403 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ObserveThing
5
+ {
6
+ public static class Settings
7
+ {
8
+ public static Action<Exception> DefaultExceptionHandler = UnityEngine.Debug.LogException;
9
+ public static ObservationContext DefaultObservationContext = new ObservationContext();
10
+ }
11
+
12
+ public interface IObserverBase
13
+ {
14
+ void OnError(Exception exc);
15
+ void OnDispose();
16
+ }
17
+
18
+ public interface IObserver<in T> : IObserverBase where T : IOperation
19
+ {
20
+ void OnNext(T operation);
21
+ }
22
+
23
+ public class Observer<T> : IObserver<T> where T : IOperation
24
+ {
25
+ private Action<T> _onNext;
26
+ private Action _onDispose;
27
+ private Action<Exception> _onError;
28
+
29
+ public Observer(Action<T> onNext = default, Action onDispose = default, Action<Exception> onError = default)
30
+ {
31
+ _onNext = onNext;
32
+ _onDispose = onDispose;
33
+ _onError = onError;
34
+ }
35
+
36
+ public void OnNext(T operation)
37
+ {
38
+ try
39
+ {
40
+ _onNext?.Invoke(operation);
41
+ }
42
+ catch (Exception exc)
43
+ {
44
+ OnError(exc);
45
+ }
46
+ }
47
+
48
+ public void OnDispose() => _onDispose?.Invoke();
49
+ public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
50
+ }
51
+
52
+ public interface IValueObserver : IObserverBase
53
+ {
54
+ void OnNext(object value);
55
+ }
56
+
57
+ public class ValueObserver : IValueObserver
58
+ {
59
+ private Action<object> _onNext;
60
+ private Action _onDispose;
61
+ private Action<Exception> _onError;
62
+
63
+ public ValueObserver(Action<object> onNext = default, Action onDispose = default, Action<Exception> onError = default)
64
+ {
65
+ _onNext = onNext;
66
+ _onDispose = onDispose;
67
+ _onError = onError;
68
+ }
69
+
70
+ public void OnNext(object value)
71
+ => _onNext?.Invoke(value);
72
+
73
+ public void OnDispose()
74
+ => _onDispose?.Invoke();
75
+
76
+ public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
77
+ }
78
+
79
+ public interface IValueObserver<in T> : IObserverBase
80
+ {
81
+ void OnNext(T value);
82
+ }
83
+
84
+ public class ValueObserver<T> : IValueObserver<T>
85
+ {
86
+ private Action<T> _onNext;
87
+ private Action _onDispose;
88
+ private Action<Exception> _onError;
89
+
90
+ public ValueObserver(Action<T> onNext = default, Action onDispose = default, Action<Exception> onError = default)
91
+ {
92
+ _onNext = onNext;
93
+ _onDispose = onDispose;
94
+ _onError = onError;
95
+ }
96
+
97
+ public void OnNext(T value)
98
+ => _onNext?.Invoke(value);
99
+
100
+ public void OnDispose()
101
+ => _onDispose?.Invoke();
102
+
103
+ public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
104
+ }
105
+
106
+ public interface ICollectionObserver : IObserverBase
107
+ {
108
+ void OnAdd(uint elementId, object element);
109
+ void OnRemove(uint elementId, object element);
110
+ }
111
+
112
+ public class CollectionObserver : ICollectionObserver
113
+ {
114
+ private Action<uint, object> _onAdd;
115
+ private Action<uint, object> _onRemove;
116
+ private Action _onDispose;
117
+ private Action<Exception> _onError;
118
+
119
+ public CollectionObserver(Action<uint, object> onAdd = default, Action<uint, object> onRemove = default, Action onDispose = default, Action<Exception> onError = default)
120
+ {
121
+ _onAdd = onAdd;
122
+ _onRemove = onRemove;
123
+ _onDispose = onDispose;
124
+ _onError = onError;
125
+ }
126
+
127
+ public void OnAdd(uint elementId, object element)
128
+ => _onAdd?.Invoke(elementId, element);
129
+
130
+ public void OnRemove(uint elementId, object element)
131
+ => _onRemove?.Invoke(elementId, element);
132
+
133
+ public void OnDispose()
134
+ => _onDispose?.Invoke();
135
+
136
+ public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
137
+ }
138
+
139
+ public interface ICollectionObserver<in T> : IObserverBase
140
+ {
141
+ void OnAdd(uint elementId, T element);
142
+ void OnRemove(uint elementId, T element);
143
+ }
144
+
145
+ public class CollectionObserver<T> : ICollectionObserver<T>
146
+ {
147
+ private Action<uint, T> _onAdd;
148
+ private Action<uint, T> _onRemove;
149
+ private Action _onDispose;
150
+ private Action<Exception> _onError;
151
+
152
+ public CollectionObserver(Action<uint, T> onAdd = default, Action<uint, T> onRemove = default, Action onDispose = default, Action<Exception> onError = default)
153
+ {
154
+ _onAdd = onAdd;
155
+ _onRemove = onRemove;
156
+ _onDispose = onDispose;
157
+ _onError = onError;
158
+ }
159
+
160
+ public void OnAdd(uint elementId, T element)
161
+ => _onAdd?.Invoke(elementId, element);
162
+
163
+ public void OnRemove(uint elementId, T element)
164
+ => _onRemove?.Invoke(elementId, element);
165
+
166
+ public void OnDispose()
167
+ => _onDispose?.Invoke();
168
+
169
+ public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
170
+ }
171
+
172
+ public interface IListObserver : IObserverBase
173
+ {
174
+ void OnAdd(uint elementId, int index, object element);
175
+ void OnRemove(uint elementId, int index, object element);
176
+ }
177
+
178
+ public class ListObserver : IListObserver
179
+ {
180
+ private Action<uint, int, object> _onAdd;
181
+ private Action<uint, int, object> _onRemove;
182
+ private Action _onDispose;
183
+ private Action<Exception> _onError;
184
+
185
+ public ListObserver(Action<uint, int, object> onAdd = default, Action<uint, int, object> onRemove = default, Action onDispose = default, Action<Exception> onError = default)
186
+ {
187
+ _onAdd = onAdd;
188
+ _onRemove = onRemove;
189
+ _onDispose = onDispose;
190
+ _onError = onError;
191
+ }
192
+
193
+ public void OnAdd(uint elementId, int index, object element)
194
+ => _onAdd?.Invoke(elementId, index, element);
195
+
196
+ public void OnRemove(uint elementId, int index, object element)
197
+ => _onRemove?.Invoke(elementId, index, element);
198
+
199
+ public void OnDispose()
200
+ => _onDispose?.Invoke();
201
+
202
+ public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
203
+ }
204
+
205
+ public interface IListObserver<in T> : IObserverBase
206
+ {
207
+ void OnAdd(uint elementId, int index, T element);
208
+ void OnRemove(uint elementId, int index, T element);
209
+ }
210
+
211
+ public class ListObserver<T> : IListObserver<T>
212
+ {
213
+ private Action<uint, int, T> _onAdd;
214
+ private Action<uint, int, T> _onRemove;
215
+ private Action _onDispose;
216
+ private Action<Exception> _onError;
217
+
218
+ public ListObserver(Action<uint, int, T> onAdd = default, Action<uint, int, T> onRemove = default, Action onDispose = default, Action<Exception> onError = default)
219
+ {
220
+ _onAdd = onAdd;
221
+ _onRemove = onRemove;
222
+ _onDispose = onDispose;
223
+ _onError = onError;
224
+ }
225
+
226
+ public void OnAdd(uint elementId, int index, T element)
227
+ => _onAdd?.Invoke(elementId, index, element);
228
+
229
+ public void OnRemove(uint elementId, int index, T element)
230
+ => _onRemove?.Invoke(elementId, index, element);
231
+
232
+ public void OnDispose()
233
+ => _onDispose?.Invoke();
234
+
235
+ public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
236
+ }
237
+
238
+ public interface ISetObserver : IObserverBase
239
+ {
240
+ void OnAdd(uint elementId, object element);
241
+ void OnRemove(uint elementId, object element);
242
+ }
243
+
244
+ public class SetObserver : ISetObserver
245
+ {
246
+ private Action<uint, object> _onAdd;
247
+ private Action<uint, object> _onRemove;
248
+ private Action _onDispose;
249
+ private Action<Exception> _onError;
250
+
251
+ public SetObserver(Action<uint, object> onAdd = default, Action<uint, object> onRemove = default, Action onDispose = default, Action<Exception> onError = default)
252
+ {
253
+ _onAdd = onAdd;
254
+ _onRemove = onRemove;
255
+ _onDispose = onDispose;
256
+ _onError = onError;
257
+ }
258
+
259
+ public void OnAdd(uint elementId, object element)
260
+ => _onAdd?.Invoke(elementId, element);
261
+
262
+ public void OnRemove(uint elementId, object element)
263
+ => _onRemove?.Invoke(elementId, element);
264
+
265
+ public void OnDispose()
266
+ => _onDispose?.Invoke();
267
+
268
+ public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
269
+ }
270
+
271
+ public interface ISetObserver<in T> : IObserverBase
272
+ {
273
+ void OnAdd(uint elementId, T element);
274
+ void OnRemove(uint elementId, T element);
275
+ }
276
+
277
+ public class SetObserver<T> : ISetObserver<T>
278
+ {
279
+ private Action<uint, T> _onAdd;
280
+ private Action<uint, T> _onRemove;
281
+ private Action _onDispose;
282
+ private Action<Exception> _onError;
283
+
284
+ public SetObserver(Action<uint, T> onAdd = default, Action<uint, T> onRemove = default, Action onDispose = default, Action<Exception> onError = default)
285
+ {
286
+ _onAdd = onAdd;
287
+ _onRemove = onRemove;
288
+ _onDispose = onDispose;
289
+ _onError = onError;
290
+ }
291
+
292
+ public void OnAdd(uint elementId, T element)
293
+ => _onAdd?.Invoke(elementId, element);
294
+
295
+ public void OnRemove(uint elementId, T element)
296
+ => _onRemove?.Invoke(elementId, element);
297
+
298
+ public void OnDispose()
299
+ => _onDispose?.Invoke();
300
+
301
+ public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
302
+ }
303
+
304
+ public interface IDictionaryObserver : IObserverBase
305
+ {
306
+ void OnAdd(uint elementId, KeyValuePair<object, object> kvp);
307
+ void OnRemove(uint elementId, KeyValuePair<object, object> kvp);
308
+ }
309
+
310
+ public class DictionaryObserver : IDictionaryObserver
311
+ {
312
+ private Action<uint, KeyValuePair<object, object>> _onAdd;
313
+ private Action<uint, KeyValuePair<object, object>> _onRemove;
314
+ private Action _onDispose;
315
+ private Action<Exception> _onError;
316
+
317
+ public DictionaryObserver(Action<uint, KeyValuePair<object, object>> onAdd = default, Action<uint, KeyValuePair<object, object>> onRemove = default, Action onDispose = default, Action<Exception> onError = default)
318
+ {
319
+ _onAdd = onAdd;
320
+ _onRemove = onRemove;
321
+ _onDispose = onDispose;
322
+ _onError = onError;
323
+ }
324
+
325
+ public void OnAdd(uint elementId, KeyValuePair<object, object> kvp)
326
+ => _onAdd?.Invoke(elementId, kvp);
327
+
328
+ public void OnRemove(uint elementId, KeyValuePair<object, object> kvp)
329
+ => _onRemove?.Invoke(elementId, kvp);
330
+
331
+ public void OnDispose()
332
+ => _onDispose?.Invoke();
333
+
334
+ public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
335
+ }
336
+
337
+ public interface IDictionaryObserver<TKey, TValue> : IObserverBase
338
+ {
339
+ void OnAdd(uint elementId, KeyValuePair<TKey, TValue> kvp);
340
+ void OnRemove(uint elementId, KeyValuePair<TKey, TValue> kvp);
341
+ }
342
+
343
+ public class DictionaryObserver<TKey, TValue> : IDictionaryObserver<TKey, TValue>
344
+ {
345
+ private Action<uint, KeyValuePair<TKey, TValue>> _onAdd;
346
+ private Action<uint, KeyValuePair<TKey, TValue>> _onRemove;
347
+ private Action _onDispose;
348
+ private Action<Exception> _onError;
349
+
350
+ public DictionaryObserver(Action<uint, KeyValuePair<TKey, TValue>> onAdd = default, Action<uint, KeyValuePair<TKey, TValue>> onRemove = default, Action onDispose = default, Action<Exception> onError = default)
351
+ {
352
+ _onAdd = onAdd;
353
+ _onRemove = onRemove;
354
+ _onDispose = onDispose;
355
+ _onError = onError;
356
+ }
357
+
358
+ public void OnAdd(uint elementId, KeyValuePair<TKey, TValue> element)
359
+ => _onAdd?.Invoke(elementId, element);
360
+
361
+ public void OnRemove(uint elementId, KeyValuePair<TKey, TValue> element)
362
+ => _onRemove?.Invoke(elementId, element);
363
+
364
+ public void OnDispose()
365
+ => _onDispose?.Invoke();
366
+
367
+ public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
368
+ }
369
+
370
+ public interface IBatchObserver<in T> : IObserverBase where T : IOperation
371
+ {
372
+ void OnNext(IReadOnlyList<T> operations);
373
+ }
374
+
375
+ public class BatchObserver<T> : IBatchObserver<T> where T : IOperation
376
+ {
377
+ private Action<IReadOnlyList<T>> _onNext;
378
+ private Action _onDispose;
379
+ private Action<Exception> _onError;
380
+
381
+ public BatchObserver(Action<IReadOnlyList<T>> onNext = default, Action onDispose = default, Action<Exception> onError = default)
382
+ {
383
+ _onNext = onNext;
384
+ _onDispose = onDispose;
385
+ _onError = onError;
386
+ }
387
+
388
+ public void OnNext(IReadOnlyList<T> args)
389
+ {
390
+ try
391
+ {
392
+ _onNext?.Invoke(args);
393
+ }
394
+ catch (Exception exc)
395
+ {
396
+ OnError(exc);
397
+ }
398
+ }
399
+
400
+ public void OnDispose() => _onDispose?.Invoke();
401
+ public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
402
+ }
403
+ }
@@ -0,0 +1,2 @@
1
+ fileFormatVersion: 2
2
+ guid: 4e4260e3c4032c642bec85861a525538
@@ -0,0 +1,71 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ObserveThing
5
+ {
6
+ public interface IBatchOp<T> : IOperation where T : IOperation
7
+ {
8
+ IReadOnlyList<T> operations { get; set; }
9
+ }
10
+
11
+ public struct BatchOp<T> : IBatchOp<T> where T : IOperation
12
+ {
13
+ public IObservable<T> source { get; set; }
14
+ public IReadOnlyList<T> operations { get; set; }
15
+
16
+ IObservable<IOperation> IOperation.source => (IObservable<IOperation>)source;
17
+ }
18
+
19
+ // public class BatchOperator<T> : ObservableBase<IBatchObserver<T>, BatchOp<T>>, IBatchOperand<T>, IBatchObservable<T> where T : IOperation
20
+ // {
21
+ // private Func<IBatchOperand<T>, IInitializationOperationsProvider<T>> _generateOperator;
22
+ // private IInitializationOperationsProvider<T> _operator;
23
+ // private bool _active = false;
24
+
25
+ // public BatchOperator(ObservationContext context, Func<IBatchOperand<T>, IInitializationOperationsProvider<T>> generateOperator) : base(context)
26
+ // {
27
+ // _generateOperator = generateOperator;
28
+ // }
29
+
30
+ // protected override void OnFirstObserverAdded()
31
+ // {
32
+ // _active = true;
33
+ // _operator = _generateOperator.Invoke(this);
34
+ // }
35
+
36
+ // protected override void OnLastObserverRemoved()
37
+ // {
38
+ // _active = false;
39
+ // _operator?.Dispose();
40
+ // _operator = null;
41
+ // }
42
+
43
+ // protected override void DisposeInternal()
44
+ // {
45
+ // _operator?.Dispose();
46
+ // _operator = null;
47
+ // }
48
+
49
+ // void IBatchOperand<T>.EnqueuePendingOperation(IReadOnlyList<T> operation)
50
+ // => EnqueuePendingOperation(new() { source = this, operations = operation });
51
+
52
+ // void IOperand.OnError(Exception error)
53
+ // => OnError(error);
54
+
55
+ // void IOperand.OnDisposed()
56
+ // {
57
+ // if (!_active)
58
+ // return;
59
+
60
+ // Dispose();
61
+ // }
62
+
63
+ // protected override IEnumerable<BatchOp<T>> GetInitializationOperations()
64
+ // {
65
+ // yield return new BatchOp<T>() { source = this, operations = _operator.GetInitializationOperations() };
66
+ // }
67
+
68
+ // protected override void SendOperation(IBatchObserver<T> observer, BatchOp<T> operation)
69
+ // => observer.OnNext(operation.operations);
70
+ // }
71
+ }
@@ -0,0 +1,2 @@
1
+ fileFormatVersion: 2
2
+ guid: 0ad77fb1c6773c540bd984e9eab9c4be
@@ -0,0 +1,30 @@
1
+ using System;
2
+
3
+ namespace ObserveThing
4
+ {
5
+ public class CollectionOperator<T> : Operator<ObservableCollection<T>>, ICollectionObservable<T>
6
+ {
7
+ public CollectionOperator(ObservationContext context, Func<ObservableCollection<T>, IDisposable> generateOperator) : base(context, generateOperator) { }
8
+
9
+ public IDisposable Subscribe(ICollectionObserver<T> observer, bool immediate = false, uint? priority = null)
10
+ {
11
+ AddObserver(observer);
12
+ var subscription = ((ICollectionObservable<T>)_observable).Subscribe(observer, immediate, priority);
13
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
14
+ }
15
+
16
+ public IDisposable Subscribe(ICollectionObserver observer, bool immediate = false, uint? priority = null)
17
+ {
18
+ AddObserver(observer);
19
+ var subscription = ((ICollectionObservable)_observable).Subscribe(observer, immediate, priority);
20
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
21
+ }
22
+
23
+ public IDisposable Subscribe(IObserver<IOperation> observer, bool immediate = false, uint? priority = null)
24
+ {
25
+ AddObserver(observer);
26
+ var subscription = ((IObservable<IOperation>)_observable).Subscribe(observer, immediate, priority);
27
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,2 @@
1
+ fileFormatVersion: 2
2
+ guid: af4ed22404cc28046b078c760a8e5699
@@ -0,0 +1,45 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ObserveThing
5
+ {
6
+ public class DictionaryOperator<TKey, TValue> : Operator<ObservableDictionary<TKey, TValue>>, IDictionaryObservable<TKey, TValue>
7
+ {
8
+ public DictionaryOperator(ObservationContext context, Func<ObservableDictionary<TKey, TValue>, IDisposable> generateOperator) : base(context, generateOperator) { }
9
+
10
+ public IDisposable Subscribe(IDictionaryObserver<TKey, TValue> observer, bool immediate = false, uint? priority = null)
11
+ {
12
+ AddObserver(observer);
13
+ var subscription = ((IDictionaryObservable<TKey, TValue>)_observable).Subscribe(observer, immediate, priority);
14
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
15
+ }
16
+
17
+ public IDisposable Subscribe(IDictionaryObserver observer, bool immediate = false, uint? priority = null)
18
+ {
19
+ AddObserver(observer);
20
+ var subscription = ((IDictionaryObservable)_observable).Subscribe(observer, immediate, priority);
21
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
22
+ }
23
+
24
+ public IDisposable Subscribe(ICollectionObserver<KeyValuePair<TKey, TValue>> observer, bool immediate = false, uint? priority = null)
25
+ {
26
+ AddObserver(observer);
27
+ var subscription = ((ICollectionObservable<KeyValuePair<TKey, TValue>>)_observable).Subscribe(observer, immediate, priority);
28
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
29
+ }
30
+
31
+ public IDisposable Subscribe(ICollectionObserver observer, bool immediate = false, uint? priority = null)
32
+ {
33
+ AddObserver(observer);
34
+ var subscription = ((ICollectionObservable)_observable).Subscribe(observer, immediate, priority);
35
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
36
+ }
37
+
38
+ public IDisposable Subscribe(IObserver<IOperation> observer, bool immediate = false, uint? priority = null)
39
+ {
40
+ AddObserver(observer);
41
+ var subscription = ((IObservable<IOperation>)_observable).Subscribe(observer, immediate, priority);
42
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,2 @@
1
+ fileFormatVersion: 2
2
+ guid: b62f5139869c71941b3648382b7dceed
@@ -0,0 +1,10 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ObserveThing
5
+ {
6
+ public interface IInitializationOperationsProvider<T> : IDisposable where T : IOperation
7
+ {
8
+ IEnumerable<T> GetInitializationOperations();
9
+ }
10
+ }
@@ -0,0 +1,2 @@
1
+ fileFormatVersion: 2
2
+ guid: d2516e2e70058d24881279e4a012bc7f
@@ -0,0 +1,44 @@
1
+ using System;
2
+
3
+ namespace ObserveThing
4
+ {
5
+ public class ListOperator<T> : Operator<ObservableList<T>>, IListObservable<T>
6
+ {
7
+ public ListOperator(ObservationContext context, Func<ObservableList<T>, IDisposable> generateOperator) : base(context, generateOperator) { }
8
+
9
+ public IDisposable Subscribe(IListObserver<T> observer, bool immediate = false, uint? priority = null)
10
+ {
11
+ AddObserver(observer);
12
+ var subscription = ((IListObservable<T>)_observable).Subscribe(observer, immediate, priority);
13
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
14
+ }
15
+
16
+ public IDisposable Subscribe(IListObserver observer, bool immediate = false, uint? priority = null)
17
+ {
18
+ AddObserver(observer);
19
+ var subscription = ((IListObservable)_observable).Subscribe(observer, immediate, priority);
20
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
21
+ }
22
+
23
+ public IDisposable Subscribe(ICollectionObserver<T> observer, bool immediate = false, uint? priority = null)
24
+ {
25
+ AddObserver(observer);
26
+ var subscription = ((ICollectionObservable<T>)_observable).Subscribe(observer, immediate, priority);
27
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
28
+ }
29
+
30
+ public IDisposable Subscribe(ICollectionObserver observer, bool immediate = false, uint? priority = null)
31
+ {
32
+ AddObserver(observer);
33
+ var subscription = ((ICollectionObservable)_observable).Subscribe(observer, immediate, priority);
34
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
35
+ }
36
+
37
+ public IDisposable Subscribe(IObserver<IOperation> observer, bool immediate = false, uint? priority = null)
38
+ {
39
+ AddObserver(observer);
40
+ var subscription = ((IObservable<IOperation>)_observable).Subscribe(observer, immediate, priority);
41
+ return new ComposedDisposable(subscription, new Disposable(() => RemoveObserver(observer)));
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,2 @@
1
+ fileFormatVersion: 2
2
+ guid: fc5ca1db7fcc0cc4b987c003b6a1026b