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.
- package/README.md +1 -1
- package/Runtime/CollectionIdProvider.cs +71 -71
- package/Runtime/CollectionIdProvider.cs.meta +1 -1
- package/Runtime/IObservable.cs +66 -66
- package/Runtime/IObservable.cs.meta +1 -1
- package/Runtime/Implementations/Observable.cs +29 -29
- package/Runtime/Implementations/Observable.cs.meta +1 -1
- package/Runtime/Implementations/ObservableBase.cs +172 -172
- package/Runtime/Implementations/ObservableBase.cs.meta +1 -1
- package/Runtime/Implementations/ObservableCollection.cs +140 -140
- package/Runtime/Implementations/ObservableCollection.cs.meta +1 -1
- package/Runtime/Implementations/ObservableDictionary.cs +165 -165
- package/Runtime/Implementations/ObservableDictionary.cs.meta +1 -1
- package/Runtime/Implementations/ObservableList.cs +162 -162
- package/Runtime/Implementations/ObservableList.cs.meta +1 -1
- package/Runtime/Implementations/ObservableSet.cs +136 -136
- package/Runtime/Implementations/ObservableSet.cs.meta +1 -1
- package/Runtime/Implementations/ObservableValue.cs +58 -58
- package/Runtime/Implementations/ObservableValue.cs.meta +1 -1
- package/Runtime/Observables/BatchObservable.cs +71 -71
- package/Runtime/Observables/BatchObservable.cs.meta +1 -1
- package/Runtime/Observables/CastObservable.cs +127 -127
- package/Runtime/Observables/CastObservable.cs.meta +1 -1
- package/Runtime/Observables/CombineObservable.cs +95 -95
- package/Runtime/Observables/CombineObservable.cs.meta +1 -1
- package/Runtime/Observables/CombineValueObservable.cs +318 -318
- package/Runtime/Observables/CombineValueObservable.cs.meta +1 -1
- package/Runtime/Observables/ConcatObservable.cs +74 -74
- package/Runtime/Observables/ConcatObservable.cs.meta +1 -1
- package/Runtime/Observables/ContainsObservable.cs +70 -70
- package/Runtime/Observables/ContainsObservable.cs.meta +1 -1
- package/Runtime/Observables/CountObservable.cs +29 -29
- package/Runtime/Observables/CountObservable.cs.meta +1 -1
- package/Runtime/Observables/DistinctObservable.cs +54 -54
- package/Runtime/Observables/DistinctObservable.cs.meta +1 -1
- package/Runtime/Observables/FirstObservable.cs +52 -52
- package/Runtime/Observables/FirstObservable.cs.meta +1 -1
- package/Runtime/Observables/IndexOfObservable.cs +82 -82
- package/Runtime/Observables/IndexOfObservable.cs.meta +1 -1
- package/Runtime/Observables/OperationStreamObservable.cs +193 -193
- package/Runtime/Observables/OperationStreamObservable.cs.meta +1 -1
- package/Runtime/Observables/OrderByObservable.cs +115 -116
- package/Runtime/Observables/OrderByObservable.cs.meta +1 -1
- package/Runtime/Observables/SelectCollectionObservable.cs +28 -28
- package/Runtime/Observables/SelectCollectionObservable.cs.meta +1 -1
- package/Runtime/Observables/SelectListObservable.cs +28 -28
- package/Runtime/Observables/SelectListObservable.cs.meta +1 -1
- package/Runtime/Observables/SelectManyObservable.cs +77 -77
- package/Runtime/Observables/SelectManyObservable.cs.meta +1 -1
- package/Runtime/Observables/SelectValueObservable.cs +27 -27
- package/Runtime/Observables/SelectValueObservable.cs.meta +1 -1
- package/Runtime/Observables/SkipWhileObservable.cs +31 -31
- package/Runtime/Observables/SkipWhileObservable.cs.meta +1 -1
- package/Runtime/Observables/ThenObservable.cs +208 -208
- package/Runtime/Observables/ThenObservable.cs.meta +1 -1
- package/Runtime/Observables/ToDictionaryObservable.cs +35 -35
- package/Runtime/Observables/ToDictionaryObservable.cs.meta +1 -1
- package/Runtime/Observables/TrackObservable.cs +74 -74
- package/Runtime/Observables/TrackObservable.cs.meta +1 -1
- package/Runtime/Observables/UnwrapCollectionObservable.cs +63 -63
- package/Runtime/Observables/UnwrapCollectionObservable.cs.meta +1 -1
- package/Runtime/Observables/UnwrapListObservable.cs +69 -69
- package/Runtime/Observables/UnwrapListObservable.cs.meta +1 -1
- package/Runtime/Observables/UnwrapValueObservable.cs +55 -55
- package/Runtime/Observables/UnwrapValueObservable.cs.meta +1 -1
- package/Runtime/Observables/WhereObservable.cs +84 -84
- package/Runtime/Observables/WhereObservable.cs.meta +1 -1
- package/Runtime/Observables/WithPreviousObservable.cs +36 -36
- package/Runtime/Observables/WithPreviousObservable.cs.meta +1 -1
- package/Runtime/Observables.cs +466 -466
- package/Runtime/Observables.meta +8 -8
- package/Runtime/ObservationContext.cs +125 -125
- package/Runtime/ObservationContext.cs.meta +1 -1
- package/Runtime/Observers.cs +402 -402
- package/Runtime/Observers.cs.meta +1 -1
- package/Runtime/Operators/BatchOperator.cs +70 -70
- package/Runtime/Operators/BatchOperator.cs.meta +1 -1
- package/Runtime/Operators/CollectionOperator.cs +30 -30
- package/Runtime/Operators/CollectionOperator.cs.meta +1 -1
- package/Runtime/Operators/DictionaryOperator.cs +45 -45
- package/Runtime/Operators/DictionaryOperator.cs.meta +1 -1
- package/Runtime/Operators/IInitializationOperationsProvider.cs +10 -10
- package/Runtime/Operators/IInitializationOperationsProvider.cs.meta +1 -1
- package/Runtime/Operators/ListOperator.cs +44 -44
- package/Runtime/Operators/ListOperator.cs.meta +1 -1
- package/Runtime/Operators/ObservableOperator.cs +74 -74
- package/Runtime/Operators/ObservableOperator.cs.meta +1 -1
- package/Runtime/Operators/Operator.cs +65 -65
- package/Runtime/Operators/Operator.cs.meta +1 -1
- package/Runtime/Operators/SetOperator.cs +44 -44
- package/Runtime/Operators/SetOperator.cs.meta +1 -1
- package/Runtime/Operators/ValueOperator.cs +29 -29
- package/Runtime/Operators/ValueOperator.cs.meta +1 -1
- package/Runtime/Operators.meta +8 -8
- package/Runtime/PriorityQueue.cs +1095 -1095
- package/Runtime/PriorityQueue.cs.meta +1 -1
- package/Tests/CollectionObservableTests.cs +738 -738
- package/Tests/DictionaryObservableTests.cs +84 -84
- package/Tests/ListObservableTests.cs +147 -147
- package/Tests/ObservationContextTests.cs +359 -359
- package/Tests/ObservationContextTests.cs.meta +1 -1
- package/Tests/ValueObservableTests.cs +321 -321
- package/package.json +24 -24
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
|
|
3
|
-
namespace ObserveThing
|
|
4
|
-
{
|
|
5
|
-
public class CastValueObservable<T> : IDisposable
|
|
6
|
-
{
|
|
7
|
-
private ObservableValue<T> _operand;
|
|
8
|
-
private IDisposable _subscription;
|
|
9
|
-
|
|
10
|
-
public CastValueObservable(IValueObservable source, ObservableValue<T> operand)
|
|
11
|
-
{
|
|
12
|
-
_operand = operand;
|
|
13
|
-
_subscription = source.Subscribe(
|
|
14
|
-
onNext: x => operand.value = (T)x,
|
|
15
|
-
onError: operand.OnError,
|
|
16
|
-
onDispose: Dispose,
|
|
17
|
-
immediate: true
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public void Dispose()
|
|
22
|
-
{
|
|
23
|
-
_subscription?.Dispose();
|
|
24
|
-
_subscription = null;
|
|
25
|
-
_operand.Dispose();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public class CastCollectionObservable<T> : IDisposable
|
|
30
|
-
{
|
|
31
|
-
private ObservableCollection<T> _operand;
|
|
32
|
-
private IDisposable _subscription;
|
|
33
|
-
|
|
34
|
-
public CastCollectionObservable(ICollectionObservable source, ObservableCollection<T> operand)
|
|
35
|
-
{
|
|
36
|
-
_operand = operand;
|
|
37
|
-
_subscription = source.SubscribeWithId(
|
|
38
|
-
onAdd: (id, x) => operand.Add(id, (T)x),
|
|
39
|
-
onRemove: (id, _) => operand.Remove(id),
|
|
40
|
-
onError: operand.OnError,
|
|
41
|
-
onDispose: Dispose,
|
|
42
|
-
immediate: true
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public void Dispose()
|
|
47
|
-
{
|
|
48
|
-
_subscription?.Dispose();
|
|
49
|
-
_subscription = null;
|
|
50
|
-
_operand.Dispose();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public class CastListObservable<T> : IDisposable
|
|
55
|
-
{
|
|
56
|
-
private ObservableList<T> _operand;
|
|
57
|
-
private IDisposable _subscription;
|
|
58
|
-
|
|
59
|
-
public CastListObservable(IListObservable source, ObservableList<T> operand)
|
|
60
|
-
{
|
|
61
|
-
_operand = operand;
|
|
62
|
-
_subscription = source.Subscribe(
|
|
63
|
-
onAdd: (index, x) => operand.Insert(index, (T)x),
|
|
64
|
-
onRemove: (index, _) => operand.RemoveAt(index),
|
|
65
|
-
onError: operand.OnError,
|
|
66
|
-
onDispose: Dispose,
|
|
67
|
-
immediate: true
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public void Dispose()
|
|
72
|
-
{
|
|
73
|
-
_subscription?.Dispose();
|
|
74
|
-
_subscription = null;
|
|
75
|
-
_operand.Dispose();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public class CastSetObservable<T> : IDisposable
|
|
80
|
-
{
|
|
81
|
-
private ObservableSet<T> _operand;
|
|
82
|
-
private IDisposable _subscription;
|
|
83
|
-
|
|
84
|
-
public CastSetObservable(ISetObservable source, ObservableSet<T> operand)
|
|
85
|
-
{
|
|
86
|
-
_operand = operand;
|
|
87
|
-
_subscription = source.Subscribe(
|
|
88
|
-
onAdd: x => operand.Add((T)x),
|
|
89
|
-
onRemove: x => operand.Remove((T)x),
|
|
90
|
-
onError: operand.OnError,
|
|
91
|
-
onDispose: Dispose,
|
|
92
|
-
immediate: true
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
public void Dispose()
|
|
97
|
-
{
|
|
98
|
-
_subscription?.Dispose();
|
|
99
|
-
_subscription = null;
|
|
100
|
-
_operand.Dispose();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public class CastDictionaryObservable<TKey, TValue> : IDisposable
|
|
105
|
-
{
|
|
106
|
-
private ObservableDictionary<TKey, TValue> _operand;
|
|
107
|
-
private IDisposable _subscription;
|
|
108
|
-
|
|
109
|
-
public CastDictionaryObservable(IDictionaryObservable source, ObservableDictionary<TKey, TValue> operand)
|
|
110
|
-
{
|
|
111
|
-
_operand = operand;
|
|
112
|
-
_subscription = source.Subscribe(
|
|
113
|
-
onAdd: x => operand.Add((TKey)x.Key, (TValue)x.Value),
|
|
114
|
-
onRemove: x => operand.Remove((TKey)x.Key),
|
|
115
|
-
onError: operand.OnError,
|
|
116
|
-
onDispose: Dispose,
|
|
117
|
-
immediate: true
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public void Dispose()
|
|
122
|
-
{
|
|
123
|
-
_subscription?.Dispose();
|
|
124
|
-
_subscription = null;
|
|
125
|
-
_operand.Dispose();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
1
|
+
using System;
|
|
2
|
+
|
|
3
|
+
namespace ObserveThing
|
|
4
|
+
{
|
|
5
|
+
public class CastValueObservable<T> : IDisposable
|
|
6
|
+
{
|
|
7
|
+
private ObservableValue<T> _operand;
|
|
8
|
+
private IDisposable _subscription;
|
|
9
|
+
|
|
10
|
+
public CastValueObservable(IValueObservable source, ObservableValue<T> operand)
|
|
11
|
+
{
|
|
12
|
+
_operand = operand;
|
|
13
|
+
_subscription = source.Subscribe(
|
|
14
|
+
onNext: x => operand.value = (T)x,
|
|
15
|
+
onError: operand.OnError,
|
|
16
|
+
onDispose: Dispose,
|
|
17
|
+
immediate: true
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public void Dispose()
|
|
22
|
+
{
|
|
23
|
+
_subscription?.Dispose();
|
|
24
|
+
_subscription = null;
|
|
25
|
+
_operand.Dispose();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public class CastCollectionObservable<T> : IDisposable
|
|
30
|
+
{
|
|
31
|
+
private ObservableCollection<T> _operand;
|
|
32
|
+
private IDisposable _subscription;
|
|
33
|
+
|
|
34
|
+
public CastCollectionObservable(ICollectionObservable source, ObservableCollection<T> operand)
|
|
35
|
+
{
|
|
36
|
+
_operand = operand;
|
|
37
|
+
_subscription = source.SubscribeWithId(
|
|
38
|
+
onAdd: (id, x) => operand.Add(id, (T)x),
|
|
39
|
+
onRemove: (id, _) => operand.Remove(id),
|
|
40
|
+
onError: operand.OnError,
|
|
41
|
+
onDispose: Dispose,
|
|
42
|
+
immediate: true
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public void Dispose()
|
|
47
|
+
{
|
|
48
|
+
_subscription?.Dispose();
|
|
49
|
+
_subscription = null;
|
|
50
|
+
_operand.Dispose();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public class CastListObservable<T> : IDisposable
|
|
55
|
+
{
|
|
56
|
+
private ObservableList<T> _operand;
|
|
57
|
+
private IDisposable _subscription;
|
|
58
|
+
|
|
59
|
+
public CastListObservable(IListObservable source, ObservableList<T> operand)
|
|
60
|
+
{
|
|
61
|
+
_operand = operand;
|
|
62
|
+
_subscription = source.Subscribe(
|
|
63
|
+
onAdd: (index, x) => operand.Insert(index, (T)x),
|
|
64
|
+
onRemove: (index, _) => operand.RemoveAt(index),
|
|
65
|
+
onError: operand.OnError,
|
|
66
|
+
onDispose: Dispose,
|
|
67
|
+
immediate: true
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public void Dispose()
|
|
72
|
+
{
|
|
73
|
+
_subscription?.Dispose();
|
|
74
|
+
_subscription = null;
|
|
75
|
+
_operand.Dispose();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public class CastSetObservable<T> : IDisposable
|
|
80
|
+
{
|
|
81
|
+
private ObservableSet<T> _operand;
|
|
82
|
+
private IDisposable _subscription;
|
|
83
|
+
|
|
84
|
+
public CastSetObservable(ISetObservable source, ObservableSet<T> operand)
|
|
85
|
+
{
|
|
86
|
+
_operand = operand;
|
|
87
|
+
_subscription = source.Subscribe(
|
|
88
|
+
onAdd: x => operand.Add((T)x),
|
|
89
|
+
onRemove: x => operand.Remove((T)x),
|
|
90
|
+
onError: operand.OnError,
|
|
91
|
+
onDispose: Dispose,
|
|
92
|
+
immediate: true
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public void Dispose()
|
|
97
|
+
{
|
|
98
|
+
_subscription?.Dispose();
|
|
99
|
+
_subscription = null;
|
|
100
|
+
_operand.Dispose();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public class CastDictionaryObservable<TKey, TValue> : IDisposable
|
|
105
|
+
{
|
|
106
|
+
private ObservableDictionary<TKey, TValue> _operand;
|
|
107
|
+
private IDisposable _subscription;
|
|
108
|
+
|
|
109
|
+
public CastDictionaryObservable(IDictionaryObservable source, ObservableDictionary<TKey, TValue> operand)
|
|
110
|
+
{
|
|
111
|
+
_operand = operand;
|
|
112
|
+
_subscription = source.Subscribe(
|
|
113
|
+
onAdd: x => operand.Add((TKey)x.Key, (TValue)x.Value),
|
|
114
|
+
onRemove: x => operand.Remove((TKey)x.Key),
|
|
115
|
+
onError: operand.OnError,
|
|
116
|
+
onDispose: Dispose,
|
|
117
|
+
immediate: true
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public void Dispose()
|
|
122
|
+
{
|
|
123
|
+
_subscription?.Dispose();
|
|
124
|
+
_subscription = null;
|
|
125
|
+
_operand.Dispose();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
128
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
1
|
+
fileFormatVersion: 2
|
|
2
2
|
guid: b01a22250763ab34aa632028afe67ef7
|
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Collections.Generic;
|
|
3
|
-
|
|
4
|
-
namespace ObserveThing
|
|
5
|
-
{
|
|
6
|
-
public class CombineObservable<T> : IInitializationOperationsProvider<T> where T : IOperation
|
|
7
|
-
{
|
|
8
|
-
private ISetObservable<IObservable<T>> _source;
|
|
9
|
-
private Observable<T> _operand;
|
|
10
|
-
private bool _disposeOnSourceEmpty;
|
|
11
|
-
private uint _elementPriority;
|
|
12
|
-
private Dictionary<IObservable<T>, IDisposable> _observables = new Dictionary<IObservable<T>, IDisposable>();
|
|
13
|
-
private IDisposable _subscriptions;
|
|
14
|
-
private bool _disposed;
|
|
15
|
-
|
|
16
|
-
public CombineObservable(ISetObservable<IObservable<T>> source, Observable<T> operand, bool disposeOnSourceEmpty = false)
|
|
17
|
-
{
|
|
18
|
-
_source = source;
|
|
19
|
-
_operand = operand;
|
|
20
|
-
_disposeOnSourceEmpty = disposeOnSourceEmpty;
|
|
21
|
-
_elementPriority = _source.context.AllocateObserverPriority();
|
|
22
|
-
_subscriptions = _source.Subscribe(new SetObserver<IObservable<T>>(
|
|
23
|
-
onAdd: HandleElementAdded,
|
|
24
|
-
onRemove: HandleElementRemoved,
|
|
25
|
-
onError: _operand.OnError,
|
|
26
|
-
onDispose: Dispose
|
|
27
|
-
), immediate: true);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public IEnumerable<T> GetInitializationOperations()
|
|
31
|
-
{
|
|
32
|
-
List<T> initOps = new List<T>();
|
|
33
|
-
|
|
34
|
-
foreach (var element in _observables.Keys)
|
|
35
|
-
{
|
|
36
|
-
var subscription = element.Subscribe(new Observer<T>(x => initOps.Add(x)));
|
|
37
|
-
subscription.Dispose();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
foreach (var op in initOps)
|
|
41
|
-
yield return op;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private void HandleElementAdded(uint _, IObservable<T> observable)
|
|
45
|
-
{
|
|
46
|
-
_observables.Add(
|
|
47
|
-
observable,
|
|
48
|
-
observable.Subscribe(new Observer<T>(
|
|
49
|
-
onNext: HandleElementChanged,
|
|
50
|
-
onError: _operand.OnError,
|
|
51
|
-
onDispose: () =>
|
|
52
|
-
{
|
|
53
|
-
if (_disposed)
|
|
54
|
-
return;
|
|
55
|
-
|
|
56
|
-
HandleElementRemoved(0, observable);
|
|
57
|
-
}
|
|
58
|
-
), immediate: true, priority: _elementPriority)
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private void HandleElementRemoved(uint _, IObservable<T> observable)
|
|
63
|
-
{
|
|
64
|
-
if (!_observables.TryGetValue(observable, out var subscription))
|
|
65
|
-
return;
|
|
66
|
-
|
|
67
|
-
_observables.Remove(observable);
|
|
68
|
-
subscription.Dispose();
|
|
69
|
-
|
|
70
|
-
if (_disposeOnSourceEmpty && _observables.Count == 0)
|
|
71
|
-
Dispose();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
protected void HandleElementChanged(T operation)
|
|
75
|
-
{
|
|
76
|
-
_operand.EnqueueOperation(operation);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public void Dispose()
|
|
80
|
-
{
|
|
81
|
-
if (_disposed)
|
|
82
|
-
return;
|
|
83
|
-
|
|
84
|
-
_disposed = true;
|
|
85
|
-
|
|
86
|
-
_source.context.DeallocateObserverPriority(_elementPriority);
|
|
87
|
-
|
|
88
|
-
foreach (var subscription in _observables.Values)
|
|
89
|
-
subscription.Dispose();
|
|
90
|
-
|
|
91
|
-
_subscriptions?.Dispose();
|
|
92
|
-
_subscriptions = null;
|
|
93
|
-
_operand.Dispose();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
|
|
4
|
+
namespace ObserveThing
|
|
5
|
+
{
|
|
6
|
+
public class CombineObservable<T> : IInitializationOperationsProvider<T> where T : IOperation
|
|
7
|
+
{
|
|
8
|
+
private ISetObservable<IObservable<T>> _source;
|
|
9
|
+
private Observable<T> _operand;
|
|
10
|
+
private bool _disposeOnSourceEmpty;
|
|
11
|
+
private uint _elementPriority;
|
|
12
|
+
private Dictionary<IObservable<T>, IDisposable> _observables = new Dictionary<IObservable<T>, IDisposable>();
|
|
13
|
+
private IDisposable _subscriptions;
|
|
14
|
+
private bool _disposed;
|
|
15
|
+
|
|
16
|
+
public CombineObservable(ISetObservable<IObservable<T>> source, Observable<T> operand, bool disposeOnSourceEmpty = false)
|
|
17
|
+
{
|
|
18
|
+
_source = source;
|
|
19
|
+
_operand = operand;
|
|
20
|
+
_disposeOnSourceEmpty = disposeOnSourceEmpty;
|
|
21
|
+
_elementPriority = _source.context.AllocateObserverPriority();
|
|
22
|
+
_subscriptions = _source.Subscribe(new SetObserver<IObservable<T>>(
|
|
23
|
+
onAdd: HandleElementAdded,
|
|
24
|
+
onRemove: HandleElementRemoved,
|
|
25
|
+
onError: _operand.OnError,
|
|
26
|
+
onDispose: Dispose
|
|
27
|
+
), immediate: true);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public IEnumerable<T> GetInitializationOperations()
|
|
31
|
+
{
|
|
32
|
+
List<T> initOps = new List<T>();
|
|
33
|
+
|
|
34
|
+
foreach (var element in _observables.Keys)
|
|
35
|
+
{
|
|
36
|
+
var subscription = element.Subscribe(new Observer<T>(x => initOps.Add(x)));
|
|
37
|
+
subscription.Dispose();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
foreach (var op in initOps)
|
|
41
|
+
yield return op;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private void HandleElementAdded(uint _, IObservable<T> observable)
|
|
45
|
+
{
|
|
46
|
+
_observables.Add(
|
|
47
|
+
observable,
|
|
48
|
+
observable.Subscribe(new Observer<T>(
|
|
49
|
+
onNext: HandleElementChanged,
|
|
50
|
+
onError: _operand.OnError,
|
|
51
|
+
onDispose: () =>
|
|
52
|
+
{
|
|
53
|
+
if (_disposed)
|
|
54
|
+
return;
|
|
55
|
+
|
|
56
|
+
HandleElementRemoved(0, observable);
|
|
57
|
+
}
|
|
58
|
+
), immediate: true, priority: _elementPriority)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private void HandleElementRemoved(uint _, IObservable<T> observable)
|
|
63
|
+
{
|
|
64
|
+
if (!_observables.TryGetValue(observable, out var subscription))
|
|
65
|
+
return;
|
|
66
|
+
|
|
67
|
+
_observables.Remove(observable);
|
|
68
|
+
subscription.Dispose();
|
|
69
|
+
|
|
70
|
+
if (_disposeOnSourceEmpty && _observables.Count == 0)
|
|
71
|
+
Dispose();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
protected void HandleElementChanged(T operation)
|
|
75
|
+
{
|
|
76
|
+
_operand.EnqueueOperation(operation);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public void Dispose()
|
|
80
|
+
{
|
|
81
|
+
if (_disposed)
|
|
82
|
+
return;
|
|
83
|
+
|
|
84
|
+
_disposed = true;
|
|
85
|
+
|
|
86
|
+
_source.context.DeallocateObserverPriority(_elementPriority);
|
|
87
|
+
|
|
88
|
+
foreach (var subscription in _observables.Values)
|
|
89
|
+
subscription.Dispose();
|
|
90
|
+
|
|
91
|
+
_subscriptions?.Dispose();
|
|
92
|
+
_subscriptions = null;
|
|
93
|
+
_operand.Dispose();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
96
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
1
|
+
fileFormatVersion: 2
|
|
2
2
|
guid: df42ce7c86dad2e42966e8238165aa40
|