com.fofx.observething 1.0.0 → 1.1.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 (103) hide show
  1. package/README.md +1 -1
  2. package/Runtime/CollectionIdProvider.cs +71 -71
  3. package/Runtime/CollectionIdProvider.cs.meta +1 -1
  4. package/Runtime/IObservable.cs +66 -66
  5. package/Runtime/IObservable.cs.meta +1 -1
  6. package/Runtime/Implementations/Observable.cs +29 -29
  7. package/Runtime/Implementations/Observable.cs.meta +1 -1
  8. package/Runtime/Implementations/ObservableBase.cs +172 -172
  9. package/Runtime/Implementations/ObservableBase.cs.meta +1 -1
  10. package/Runtime/Implementations/ObservableCollection.cs +140 -140
  11. package/Runtime/Implementations/ObservableCollection.cs.meta +1 -1
  12. package/Runtime/Implementations/ObservableDictionary.cs +165 -165
  13. package/Runtime/Implementations/ObservableDictionary.cs.meta +1 -1
  14. package/Runtime/Implementations/ObservableList.cs +162 -162
  15. package/Runtime/Implementations/ObservableList.cs.meta +1 -1
  16. package/Runtime/Implementations/ObservableSet.cs +136 -136
  17. package/Runtime/Implementations/ObservableSet.cs.meta +1 -1
  18. package/Runtime/Implementations/ObservableValue.cs +58 -58
  19. package/Runtime/Implementations/ObservableValue.cs.meta +1 -1
  20. package/Runtime/Observables/BatchObservable.cs +71 -71
  21. package/Runtime/Observables/BatchObservable.cs.meta +1 -1
  22. package/Runtime/Observables/CastObservable.cs +127 -127
  23. package/Runtime/Observables/CastObservable.cs.meta +1 -1
  24. package/Runtime/Observables/CombineObservable.cs +95 -95
  25. package/Runtime/Observables/CombineObservable.cs.meta +1 -1
  26. package/Runtime/Observables/CombineValueObservable.cs +318 -318
  27. package/Runtime/Observables/CombineValueObservable.cs.meta +1 -1
  28. package/Runtime/Observables/ConcatObservable.cs +74 -74
  29. package/Runtime/Observables/ConcatObservable.cs.meta +1 -1
  30. package/Runtime/Observables/ContainsObservable.cs +70 -70
  31. package/Runtime/Observables/ContainsObservable.cs.meta +1 -1
  32. package/Runtime/Observables/CountObservable.cs +29 -29
  33. package/Runtime/Observables/CountObservable.cs.meta +1 -1
  34. package/Runtime/Observables/DistinctObservable.cs +54 -54
  35. package/Runtime/Observables/DistinctObservable.cs.meta +1 -1
  36. package/Runtime/Observables/FirstObservable.cs +52 -52
  37. package/Runtime/Observables/FirstObservable.cs.meta +1 -1
  38. package/Runtime/Observables/IndexOfObservable.cs +82 -82
  39. package/Runtime/Observables/IndexOfObservable.cs.meta +1 -1
  40. package/Runtime/Observables/OperationStreamObservable.cs +193 -193
  41. package/Runtime/Observables/OperationStreamObservable.cs.meta +1 -1
  42. package/Runtime/Observables/OrderByObservable.cs +115 -116
  43. package/Runtime/Observables/OrderByObservable.cs.meta +1 -1
  44. package/Runtime/Observables/SelectCollectionObservable.cs +28 -28
  45. package/Runtime/Observables/SelectCollectionObservable.cs.meta +1 -1
  46. package/Runtime/Observables/SelectListObservable.cs +28 -28
  47. package/Runtime/Observables/SelectListObservable.cs.meta +1 -1
  48. package/Runtime/Observables/SelectManyObservable.cs +77 -77
  49. package/Runtime/Observables/SelectManyObservable.cs.meta +1 -1
  50. package/Runtime/Observables/SelectValueObservable.cs +27 -27
  51. package/Runtime/Observables/SelectValueObservable.cs.meta +1 -1
  52. package/Runtime/Observables/SkipWhileObservable.cs +31 -31
  53. package/Runtime/Observables/SkipWhileObservable.cs.meta +1 -1
  54. package/Runtime/Observables/ThenObservable.cs +208 -208
  55. package/Runtime/Observables/ThenObservable.cs.meta +1 -1
  56. package/Runtime/Observables/ToDictionaryObservable.cs +35 -35
  57. package/Runtime/Observables/ToDictionaryObservable.cs.meta +1 -1
  58. package/Runtime/Observables/TrackObservable.cs +74 -74
  59. package/Runtime/Observables/TrackObservable.cs.meta +1 -1
  60. package/Runtime/Observables/UnwrapCollectionObservable.cs +63 -63
  61. package/Runtime/Observables/UnwrapCollectionObservable.cs.meta +1 -1
  62. package/Runtime/Observables/UnwrapListObservable.cs +69 -69
  63. package/Runtime/Observables/UnwrapListObservable.cs.meta +1 -1
  64. package/Runtime/Observables/UnwrapValueObservable.cs +55 -55
  65. package/Runtime/Observables/UnwrapValueObservable.cs.meta +1 -1
  66. package/Runtime/Observables/WhereObservable.cs +84 -84
  67. package/Runtime/Observables/WhereObservable.cs.meta +1 -1
  68. package/Runtime/Observables/WithPreviousObservable.cs +36 -36
  69. package/Runtime/Observables/WithPreviousObservable.cs.meta +1 -1
  70. package/Runtime/Observables.cs +466 -466
  71. package/Runtime/Observables.meta +8 -8
  72. package/Runtime/ObservationContext.cs +125 -125
  73. package/Runtime/ObservationContext.cs.meta +1 -1
  74. package/Runtime/Observers.cs +402 -402
  75. package/Runtime/Observers.cs.meta +1 -1
  76. package/Runtime/Operators/BatchOperator.cs +70 -70
  77. package/Runtime/Operators/BatchOperator.cs.meta +1 -1
  78. package/Runtime/Operators/CollectionOperator.cs +30 -30
  79. package/Runtime/Operators/CollectionOperator.cs.meta +1 -1
  80. package/Runtime/Operators/DictionaryOperator.cs +45 -45
  81. package/Runtime/Operators/DictionaryOperator.cs.meta +1 -1
  82. package/Runtime/Operators/IInitializationOperationsProvider.cs +10 -10
  83. package/Runtime/Operators/IInitializationOperationsProvider.cs.meta +1 -1
  84. package/Runtime/Operators/ListOperator.cs +44 -44
  85. package/Runtime/Operators/ListOperator.cs.meta +1 -1
  86. package/Runtime/Operators/ObservableOperator.cs +74 -74
  87. package/Runtime/Operators/ObservableOperator.cs.meta +1 -1
  88. package/Runtime/Operators/Operator.cs +65 -65
  89. package/Runtime/Operators/Operator.cs.meta +1 -1
  90. package/Runtime/Operators/SetOperator.cs +44 -44
  91. package/Runtime/Operators/SetOperator.cs.meta +1 -1
  92. package/Runtime/Operators/ValueOperator.cs +29 -29
  93. package/Runtime/Operators/ValueOperator.cs.meta +1 -1
  94. package/Runtime/Operators.meta +8 -8
  95. package/Runtime/PriorityQueue.cs +1095 -1095
  96. package/Runtime/PriorityQueue.cs.meta +1 -1
  97. package/Tests/CollectionObservableTests.cs +738 -738
  98. package/Tests/DictionaryObservableTests.cs +84 -84
  99. package/Tests/ListObservableTests.cs +147 -147
  100. package/Tests/ObservationContextTests.cs +359 -359
  101. package/Tests/ObservationContextTests.cs.meta +1 -1
  102. package/Tests/ValueObservableTests.cs +321 -321
  103. package/package.json +24 -24
@@ -1,83 +1,83 @@
1
- using System;
2
- using System.Collections.Generic;
3
-
4
- namespace ObserveThing
5
- {
6
- public class IndexOfObservable<T> : IDisposable
7
- {
8
- private ObservableValue<(bool found, int index)> _operand;
9
- private T _latest = default;
10
- private List<T> _list = new List<T>();
11
- private IDisposable _subscriptions;
12
-
13
- public IndexOfObservable(IListObservable<T> source, IValueObservable<T> value, ObservableValue<(bool found, int index)> operand)
14
- {
15
- _operand = operand;
16
- _subscriptions = new ComposedDisposable(
17
-
18
- value.Subscribe(
19
- onNext: HandleNext,
20
- onError: operand.OnError,
21
- onDispose: Dispose,
22
- immediate: true
23
- ),
24
-
25
- source.Subscribe(
26
- onAdd: HandleAdd,
27
- onRemove: HandleRemove,
28
- onError: operand.OnError,
29
- onDispose: Dispose,
30
- immediate: true
31
- )
32
-
33
- );
34
- }
35
-
36
- private void HandleAdd(int index, T element)
37
- {
38
- _list.Insert(index, element);
39
- UpdateIndexIfNecessary();
40
- }
41
-
42
- private void HandleRemove(int index, T element)
43
- {
44
- _list.RemoveAt(index);
45
- UpdateIndexIfNecessary();
46
- }
47
-
48
- private void HandleNext(T value)
49
- {
50
- _latest = value;
51
- UpdateIndexIfNecessary();
52
- }
53
-
54
- private void UpdateIndexIfNecessary()
55
- {
56
- var newIndex = -1;
57
-
58
- for (int i = 0; i < _list.Count; i++)
59
- {
60
- if (Equals(_latest, _list[i]))
61
- {
62
- newIndex = i;
63
- break;
64
- }
65
- }
66
-
67
- if (newIndex == -1)
68
- {
69
- _operand.value = default;
70
- return;
71
- }
72
-
73
- _operand.value = new(true, newIndex);
74
- }
75
-
76
- public void Dispose()
77
- {
78
- _subscriptions?.Dispose();
79
- _subscriptions = null;
80
- _operand.Dispose();
81
- }
82
- }
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ObserveThing
5
+ {
6
+ public class IndexOfObservable<T> : IDisposable
7
+ {
8
+ private ObservableValue<(bool found, int index)> _operand;
9
+ private T _latest = default;
10
+ private List<T> _list = new List<T>();
11
+ private IDisposable _subscriptions;
12
+
13
+ public IndexOfObservable(IListObservable<T> source, IValueObservable<T> value, ObservableValue<(bool found, int index)> operand)
14
+ {
15
+ _operand = operand;
16
+ _subscriptions = new ComposedDisposable(
17
+
18
+ value.Subscribe(
19
+ onNext: HandleNext,
20
+ onError: operand.OnError,
21
+ onDispose: Dispose,
22
+ immediate: true
23
+ ),
24
+
25
+ source.Subscribe(
26
+ onAdd: HandleAdd,
27
+ onRemove: HandleRemove,
28
+ onError: operand.OnError,
29
+ onDispose: Dispose,
30
+ immediate: true
31
+ )
32
+
33
+ );
34
+ }
35
+
36
+ private void HandleAdd(int index, T element)
37
+ {
38
+ _list.Insert(index, element);
39
+ UpdateIndexIfNecessary();
40
+ }
41
+
42
+ private void HandleRemove(int index, T element)
43
+ {
44
+ _list.RemoveAt(index);
45
+ UpdateIndexIfNecessary();
46
+ }
47
+
48
+ private void HandleNext(T value)
49
+ {
50
+ _latest = value;
51
+ UpdateIndexIfNecessary();
52
+ }
53
+
54
+ private void UpdateIndexIfNecessary()
55
+ {
56
+ var newIndex = -1;
57
+
58
+ for (int i = 0; i < _list.Count; i++)
59
+ {
60
+ if (Equals(_latest, _list[i]))
61
+ {
62
+ newIndex = i;
63
+ break;
64
+ }
65
+ }
66
+
67
+ if (newIndex == -1)
68
+ {
69
+ _operand.value = default;
70
+ return;
71
+ }
72
+
73
+ _operand.value = new(true, newIndex);
74
+ }
75
+
76
+ public void Dispose()
77
+ {
78
+ _subscriptions?.Dispose();
79
+ _subscriptions = null;
80
+ _operand.Dispose();
81
+ }
82
+ }
83
83
  }
@@ -1,2 +1,2 @@
1
- fileFormatVersion: 2
1
+ fileFormatVersion: 2
2
2
  guid: d70f17a6cc8ad6c459951f817e159eef
@@ -1,194 +1,194 @@
1
- using System;
2
- using System.Collections.Generic;
3
-
4
- namespace ObserveThing
5
- {
6
- public class ValueOperationStreamObservable<T> : IInitializationOperationsProvider<ValueOp<T>>, IDisposable
7
- {
8
- private IValueObservable<T> _source;
9
- private Observable<ValueOp<T>> _operand;
10
- private IDisposable _subscriptions;
11
-
12
- public ValueOperationStreamObservable(IValueObservable<T> source, Observable<ValueOp<T>> operand)
13
- {
14
- _source = source;
15
- _operand = operand;
16
-
17
- _subscriptions = _source.Subscribe(
18
- onNext: x => operand.EnqueueOperation(new() { source = _source, value = x }),
19
- onDispose: Dispose,
20
- onError: operand.OnError,
21
- immediate: true
22
- );
23
- }
24
-
25
- public IEnumerable<ValueOp<T>> GetInitializationOperations()
26
- {
27
- var initOperations = new List<ValueOp<T>>();
28
- var subscription = _source.Subscribe(x => initOperations.Add(new ValueOp<T>() { source = _source, value = x }));
29
- subscription.Dispose();
30
-
31
- foreach (var op in initOperations)
32
- yield return op;
33
- }
34
-
35
- public void Dispose()
36
- {
37
- _subscriptions?.Dispose();
38
- _subscriptions = null;
39
- _operand.Dispose();
40
- }
41
- }
42
-
43
- public class CollectionOperationStreamObservable<T> : IInitializationOperationsProvider<CollectionOp<T>>, IDisposable
44
- {
45
- private ICollectionObservable<T> _source;
46
- private Observable<CollectionOp<T>> _operand;
47
- private IDisposable _subscriptions;
48
-
49
- public CollectionOperationStreamObservable(ICollectionObservable<T> source, Observable<CollectionOp<T>> operand)
50
- {
51
- _source = source;
52
- _operand = operand;
53
-
54
- _subscriptions = _source.SubscribeWithId(
55
- onAdd: (id, element) => operand.EnqueueOperation(new() { source = _source, elementId = id, element = element, isRemove = false }),
56
- onRemove: (id, element) => operand.EnqueueOperation(new() { source = _source, elementId = id, element = element, isRemove = true }),
57
- onDispose: Dispose,
58
- onError: operand.OnError,
59
- immediate: true
60
- );
61
- }
62
-
63
- public IEnumerable<CollectionOp<T>> GetInitializationOperations()
64
- {
65
- var initOperations = new List<CollectionOp<T>>();
66
- var subscription = _source.SubscribeWithId((id, element) => initOperations.Add(new CollectionOp<T>() { source = _source, elementId = id, element = element }));
67
- subscription.Dispose();
68
-
69
- foreach (var op in initOperations)
70
- yield return op;
71
- }
72
-
73
- public void Dispose()
74
- {
75
- _subscriptions?.Dispose();
76
- _subscriptions = null;
77
- _operand.Dispose();
78
- }
79
- }
80
-
81
- public class ListOperationStreamObservable<T> : IInitializationOperationsProvider<ListOp<T>>, IDisposable
82
- {
83
- private IListObservable<T> _source;
84
- private Observable<ListOp<T>> _operand;
85
- private IDisposable _subscriptions;
86
-
87
- public ListOperationStreamObservable(IListObservable<T> source, Observable<ListOp<T>> operand)
88
- {
89
- _source = source;
90
- _operand = operand;
91
-
92
- _subscriptions = _source.SubscribeWithId(
93
- onAdd: (id, index, element) => operand.EnqueueOperation(new() { source = _source, elementId = id, index = index, element = element, isRemove = false }),
94
- onRemove: (id, index, element) => operand.EnqueueOperation(new() { source = _source, elementId = id, index = index, element = element, isRemove = true }),
95
- onDispose: Dispose,
96
- onError: operand.OnError,
97
- immediate: true
98
- );
99
- }
100
-
101
- public IEnumerable<ListOp<T>> GetInitializationOperations()
102
- {
103
- var initOperations = new List<ListOp<T>>();
104
- var subscription = _source.SubscribeWithId((id, index, element) => initOperations.Add(new ListOp<T>() { source = _source, elementId = id, index = index, element = element }));
105
- subscription.Dispose();
106
-
107
- foreach (var op in initOperations)
108
- yield return op;
109
- }
110
-
111
- public void Dispose()
112
- {
113
- _subscriptions?.Dispose();
114
- _subscriptions = null;
115
- _operand.Dispose();
116
- }
117
- }
118
-
119
- public class DictionaryOperationStreamObservable<TKey, TValue> : IInitializationOperationsProvider<DictionaryOp<TKey, TValue>>, IDisposable
120
- {
121
- private IDictionaryObservable<TKey, TValue> _source;
122
- private Observable<DictionaryOp<TKey, TValue>> _operand;
123
- private IDisposable _subscriptions;
124
-
125
- public DictionaryOperationStreamObservable(IDictionaryObservable<TKey, TValue> source, Observable<DictionaryOp<TKey, TValue>> operand)
126
- {
127
- _source = source;
128
- _operand = operand;
129
-
130
- _subscriptions = _source.SubscribeWithId(
131
- onAdd: (id, kvp) => operand.EnqueueOperation(new() { source = _source, elementId = id, key = kvp.Key, value = kvp.Value, isRemove = false }),
132
- onRemove: (id, kvp) => operand.EnqueueOperation(new() { source = _source, elementId = id, key = kvp.Key, value = kvp.Value, isRemove = true }),
133
- onDispose: Dispose,
134
- onError: operand.OnError,
135
- immediate: true
136
- );
137
- }
138
-
139
- public IEnumerable<DictionaryOp<TKey, TValue>> GetInitializationOperations()
140
- {
141
- var initOperations = new List<DictionaryOp<TKey, TValue>>();
142
- var subscription = _source.SubscribeWithId((id, kvp) => initOperations.Add(new DictionaryOp<TKey, TValue>() { source = _source, elementId = id, key = kvp.Key, value = kvp.Value }));
143
- subscription.Dispose();
144
-
145
- foreach (var op in initOperations)
146
- yield return op;
147
- }
148
-
149
- public void Dispose()
150
- {
151
- _subscriptions?.Dispose();
152
- _subscriptions = null;
153
- _operand.Dispose();
154
- }
155
- }
156
-
157
- public class SetOperationStreamObservable<T> : IInitializationOperationsProvider<SetOp<T>>, IDisposable
158
- {
159
- private ISetObservable<T> _source;
160
- private Observable<SetOp<T>> _operand;
161
- private IDisposable _subscriptions;
162
-
163
- public SetOperationStreamObservable(ISetObservable<T> source, Observable<SetOp<T>> operand)
164
- {
165
- _source = source;
166
- _operand = operand;
167
-
168
- _subscriptions = _source.SubscribeWithId(
169
- onAdd: (id, element) => operand.EnqueueOperation(new() { source = _source, elementId = id, element = element, isRemove = false }),
170
- onRemove: (id, element) => operand.EnqueueOperation(new() { source = _source, elementId = id, element = element, isRemove = true }),
171
- onDispose: Dispose,
172
- onError: operand.OnError,
173
- immediate: true
174
- );
175
- }
176
-
177
- public IEnumerable<SetOp<T>> GetInitializationOperations()
178
- {
179
- var initOperations = new List<SetOp<T>>();
180
- var subscription = _source.SubscribeWithId((id, element) => initOperations.Add(new SetOp<T>() { source = _source, elementId = id, element = element }));
181
- subscription.Dispose();
182
-
183
- foreach (var op in initOperations)
184
- yield return op;
185
- }
186
-
187
- public void Dispose()
188
- {
189
- _subscriptions?.Dispose();
190
- _subscriptions = null;
191
- _operand.Dispose();
192
- }
193
- }
1
+ using System;
2
+ using System.Collections.Generic;
3
+
4
+ namespace ObserveThing
5
+ {
6
+ public class ValueOperationStreamObservable<T> : IInitializationOperationsProvider<ValueOp<T>>, IDisposable
7
+ {
8
+ private IValueObservable<T> _source;
9
+ private Observable<ValueOp<T>> _operand;
10
+ private IDisposable _subscriptions;
11
+
12
+ public ValueOperationStreamObservable(IValueObservable<T> source, Observable<ValueOp<T>> operand)
13
+ {
14
+ _source = source;
15
+ _operand = operand;
16
+
17
+ _subscriptions = _source.Subscribe(
18
+ onNext: x => operand.EnqueueOperation(new() { source = _source, value = x }),
19
+ onDispose: Dispose,
20
+ onError: operand.OnError,
21
+ immediate: true
22
+ );
23
+ }
24
+
25
+ public IEnumerable<ValueOp<T>> GetInitializationOperations()
26
+ {
27
+ var initOperations = new List<ValueOp<T>>();
28
+ var subscription = _source.Subscribe(x => initOperations.Add(new ValueOp<T>() { source = _source, value = x }));
29
+ subscription.Dispose();
30
+
31
+ foreach (var op in initOperations)
32
+ yield return op;
33
+ }
34
+
35
+ public void Dispose()
36
+ {
37
+ _subscriptions?.Dispose();
38
+ _subscriptions = null;
39
+ _operand.Dispose();
40
+ }
41
+ }
42
+
43
+ public class CollectionOperationStreamObservable<T> : IInitializationOperationsProvider<CollectionOp<T>>, IDisposable
44
+ {
45
+ private ICollectionObservable<T> _source;
46
+ private Observable<CollectionOp<T>> _operand;
47
+ private IDisposable _subscriptions;
48
+
49
+ public CollectionOperationStreamObservable(ICollectionObservable<T> source, Observable<CollectionOp<T>> operand)
50
+ {
51
+ _source = source;
52
+ _operand = operand;
53
+
54
+ _subscriptions = _source.SubscribeWithId(
55
+ onAdd: (id, element) => operand.EnqueueOperation(new() { source = _source, elementId = id, element = element, isRemove = false }),
56
+ onRemove: (id, element) => operand.EnqueueOperation(new() { source = _source, elementId = id, element = element, isRemove = true }),
57
+ onDispose: Dispose,
58
+ onError: operand.OnError,
59
+ immediate: true
60
+ );
61
+ }
62
+
63
+ public IEnumerable<CollectionOp<T>> GetInitializationOperations()
64
+ {
65
+ var initOperations = new List<CollectionOp<T>>();
66
+ var subscription = _source.SubscribeWithId((id, element) => initOperations.Add(new CollectionOp<T>() { source = _source, elementId = id, element = element }));
67
+ subscription.Dispose();
68
+
69
+ foreach (var op in initOperations)
70
+ yield return op;
71
+ }
72
+
73
+ public void Dispose()
74
+ {
75
+ _subscriptions?.Dispose();
76
+ _subscriptions = null;
77
+ _operand.Dispose();
78
+ }
79
+ }
80
+
81
+ public class ListOperationStreamObservable<T> : IInitializationOperationsProvider<ListOp<T>>, IDisposable
82
+ {
83
+ private IListObservable<T> _source;
84
+ private Observable<ListOp<T>> _operand;
85
+ private IDisposable _subscriptions;
86
+
87
+ public ListOperationStreamObservable(IListObservable<T> source, Observable<ListOp<T>> operand)
88
+ {
89
+ _source = source;
90
+ _operand = operand;
91
+
92
+ _subscriptions = _source.SubscribeWithId(
93
+ onAdd: (id, index, element) => operand.EnqueueOperation(new() { source = _source, elementId = id, index = index, element = element, isRemove = false }),
94
+ onRemove: (id, index, element) => operand.EnqueueOperation(new() { source = _source, elementId = id, index = index, element = element, isRemove = true }),
95
+ onDispose: Dispose,
96
+ onError: operand.OnError,
97
+ immediate: true
98
+ );
99
+ }
100
+
101
+ public IEnumerable<ListOp<T>> GetInitializationOperations()
102
+ {
103
+ var initOperations = new List<ListOp<T>>();
104
+ var subscription = _source.SubscribeWithId((id, index, element) => initOperations.Add(new ListOp<T>() { source = _source, elementId = id, index = index, element = element }));
105
+ subscription.Dispose();
106
+
107
+ foreach (var op in initOperations)
108
+ yield return op;
109
+ }
110
+
111
+ public void Dispose()
112
+ {
113
+ _subscriptions?.Dispose();
114
+ _subscriptions = null;
115
+ _operand.Dispose();
116
+ }
117
+ }
118
+
119
+ public class DictionaryOperationStreamObservable<TKey, TValue> : IInitializationOperationsProvider<DictionaryOp<TKey, TValue>>, IDisposable
120
+ {
121
+ private IDictionaryObservable<TKey, TValue> _source;
122
+ private Observable<DictionaryOp<TKey, TValue>> _operand;
123
+ private IDisposable _subscriptions;
124
+
125
+ public DictionaryOperationStreamObservable(IDictionaryObservable<TKey, TValue> source, Observable<DictionaryOp<TKey, TValue>> operand)
126
+ {
127
+ _source = source;
128
+ _operand = operand;
129
+
130
+ _subscriptions = _source.SubscribeWithId(
131
+ onAdd: (id, kvp) => operand.EnqueueOperation(new() { source = _source, elementId = id, key = kvp.Key, value = kvp.Value, isRemove = false }),
132
+ onRemove: (id, kvp) => operand.EnqueueOperation(new() { source = _source, elementId = id, key = kvp.Key, value = kvp.Value, isRemove = true }),
133
+ onDispose: Dispose,
134
+ onError: operand.OnError,
135
+ immediate: true
136
+ );
137
+ }
138
+
139
+ public IEnumerable<DictionaryOp<TKey, TValue>> GetInitializationOperations()
140
+ {
141
+ var initOperations = new List<DictionaryOp<TKey, TValue>>();
142
+ var subscription = _source.SubscribeWithId((id, kvp) => initOperations.Add(new DictionaryOp<TKey, TValue>() { source = _source, elementId = id, key = kvp.Key, value = kvp.Value }));
143
+ subscription.Dispose();
144
+
145
+ foreach (var op in initOperations)
146
+ yield return op;
147
+ }
148
+
149
+ public void Dispose()
150
+ {
151
+ _subscriptions?.Dispose();
152
+ _subscriptions = null;
153
+ _operand.Dispose();
154
+ }
155
+ }
156
+
157
+ public class SetOperationStreamObservable<T> : IInitializationOperationsProvider<SetOp<T>>, IDisposable
158
+ {
159
+ private ISetObservable<T> _source;
160
+ private Observable<SetOp<T>> _operand;
161
+ private IDisposable _subscriptions;
162
+
163
+ public SetOperationStreamObservable(ISetObservable<T> source, Observable<SetOp<T>> operand)
164
+ {
165
+ _source = source;
166
+ _operand = operand;
167
+
168
+ _subscriptions = _source.SubscribeWithId(
169
+ onAdd: (id, element) => operand.EnqueueOperation(new() { source = _source, elementId = id, element = element, isRemove = false }),
170
+ onRemove: (id, element) => operand.EnqueueOperation(new() { source = _source, elementId = id, element = element, isRemove = true }),
171
+ onDispose: Dispose,
172
+ onError: operand.OnError,
173
+ immediate: true
174
+ );
175
+ }
176
+
177
+ public IEnumerable<SetOp<T>> GetInitializationOperations()
178
+ {
179
+ var initOperations = new List<SetOp<T>>();
180
+ var subscription = _source.SubscribeWithId((id, element) => initOperations.Add(new SetOp<T>() { source = _source, elementId = id, element = element }));
181
+ subscription.Dispose();
182
+
183
+ foreach (var op in initOperations)
184
+ yield return op;
185
+ }
186
+
187
+ public void Dispose()
188
+ {
189
+ _subscriptions?.Dispose();
190
+ _subscriptions = null;
191
+ _operand.Dispose();
192
+ }
193
+ }
194
194
  }
@@ -1,2 +1,2 @@
1
- fileFormatVersion: 2
1
+ fileFormatVersion: 2
2
2
  guid: a8b84513c7f460345a3647da3b5f406a