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,116 +1,115 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Collections.Generic;
|
|
3
|
-
using System.Linq;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
private
|
|
11
|
-
private Func<
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
public
|
|
20
|
-
public
|
|
21
|
-
public
|
|
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
|
-
data
|
|
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
|
-
_subscriptions
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Linq;
|
|
4
|
+
|
|
5
|
+
namespace ObserveThing
|
|
6
|
+
{
|
|
7
|
+
public class OrderByObservable<T, U> : IDisposable
|
|
8
|
+
{
|
|
9
|
+
private ObservableList<T> _operand;
|
|
10
|
+
private Func<T, IValueObservable<U>> _orderBy;
|
|
11
|
+
private Func<U, U, int> _compare;
|
|
12
|
+
private Dictionary<uint, EntryData> _dataById = new Dictionary<uint, EntryData>();
|
|
13
|
+
private List<EntryData> _order = new List<EntryData>();
|
|
14
|
+
private IDisposable _subscriptions;
|
|
15
|
+
|
|
16
|
+
private class EntryData
|
|
17
|
+
{
|
|
18
|
+
public uint id;
|
|
19
|
+
public T element;
|
|
20
|
+
public U orderBy;
|
|
21
|
+
public IDisposable subscription;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public OrderByObservable(ICollectionObservable<T> source, Func<T, IValueObservable<U>> orderBy, bool descending, ObservableList<T> operand)
|
|
25
|
+
{
|
|
26
|
+
_orderBy = orderBy;
|
|
27
|
+
_compare = descending ? DescendingCompare : AscendingCompare;
|
|
28
|
+
_operand = operand;
|
|
29
|
+
_subscriptions = source.SubscribeWithId(
|
|
30
|
+
onAdd: HandleAdd,
|
|
31
|
+
onRemove: HandleRemove,
|
|
32
|
+
onError: _operand.OnError,
|
|
33
|
+
onDispose: Dispose,
|
|
34
|
+
immediate: true
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private int DescendingCompare(U v1, U v2)
|
|
39
|
+
=> Comparer<U>.Default.Compare(v2, v1);
|
|
40
|
+
|
|
41
|
+
private int AscendingCompare(U v1, U v2)
|
|
42
|
+
=> Comparer<U>.Default.Compare(v1, v2);
|
|
43
|
+
|
|
44
|
+
private void HandleAdd(uint id, T element)
|
|
45
|
+
{
|
|
46
|
+
var data = new EntryData()
|
|
47
|
+
{
|
|
48
|
+
id = id,
|
|
49
|
+
element = element
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
_dataById.Add(id, data);
|
|
53
|
+
data.subscription = _orderBy(element).Subscribe(
|
|
54
|
+
onNext: x =>
|
|
55
|
+
{
|
|
56
|
+
data.orderBy = x;
|
|
57
|
+
Resort(data);
|
|
58
|
+
},
|
|
59
|
+
onError: _operand.OnError,
|
|
60
|
+
immediate: true
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private void HandleRemove(uint id, T element)
|
|
65
|
+
{
|
|
66
|
+
var data = _dataById[id];
|
|
67
|
+
int index = _order.IndexOf(data);
|
|
68
|
+
_dataById.Remove(id);
|
|
69
|
+
_order.RemoveAt(index);
|
|
70
|
+
data.subscription.Dispose();
|
|
71
|
+
_operand.RemoveAt(index);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private void Resort(EntryData data)
|
|
75
|
+
{
|
|
76
|
+
var originalIndex = _order.IndexOf(data);
|
|
77
|
+
|
|
78
|
+
if (originalIndex != -1)
|
|
79
|
+
_order.RemoveAt(originalIndex);
|
|
80
|
+
|
|
81
|
+
int newIndex = -1;
|
|
82
|
+
|
|
83
|
+
for (int i = 0; i < _order.Count; i++)
|
|
84
|
+
{
|
|
85
|
+
var compareTo = _order[i];
|
|
86
|
+
|
|
87
|
+
if (_compare(data.orderBy, compareTo.orderBy) > 0)
|
|
88
|
+
continue;
|
|
89
|
+
|
|
90
|
+
newIndex = i;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (newIndex == -1)
|
|
95
|
+
newIndex = _order.Count;
|
|
96
|
+
|
|
97
|
+
_order.Insert(newIndex, data);
|
|
98
|
+
|
|
99
|
+
if (originalIndex != newIndex)
|
|
100
|
+
{
|
|
101
|
+
if (originalIndex != -1)
|
|
102
|
+
_operand.RemoveAt(originalIndex);
|
|
103
|
+
|
|
104
|
+
_operand.Insert(newIndex, data.element);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public void Dispose()
|
|
109
|
+
{
|
|
110
|
+
_subscriptions?.Dispose();
|
|
111
|
+
_subscriptions = null;
|
|
112
|
+
_operand.Dispose();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
1
|
+
fileFormatVersion: 2
|
|
2
2
|
guid: 9767c296c184882418b155dcf5bbabe7
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
|
|
3
|
-
namespace ObserveThing
|
|
4
|
-
{
|
|
5
|
-
public class SelectCollectionObservable<T, U> : IDisposable
|
|
6
|
-
{
|
|
7
|
-
private ObservableCollection<U> _operand;
|
|
8
|
-
private IDisposable _subscriptions;
|
|
9
|
-
|
|
10
|
-
public SelectCollectionObservable(ICollectionObservable<T> source, Func<T, U> select, ObservableCollection<U> operand)
|
|
11
|
-
{
|
|
12
|
-
_operand = operand;
|
|
13
|
-
_subscriptions = source.SubscribeWithId(
|
|
14
|
-
onAdd: (id, value) => operand.Add(id, select(value)),
|
|
15
|
-
onRemove: (id, _) => operand.Remove(id),
|
|
16
|
-
onError: operand.OnError,
|
|
17
|
-
onDispose: Dispose,
|
|
18
|
-
immediate: true
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public void Dispose()
|
|
23
|
-
{
|
|
24
|
-
_subscriptions?.Dispose();
|
|
25
|
-
_subscriptions = null;
|
|
26
|
-
_operand.Dispose();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
using System;
|
|
2
|
+
|
|
3
|
+
namespace ObserveThing
|
|
4
|
+
{
|
|
5
|
+
public class SelectCollectionObservable<T, U> : IDisposable
|
|
6
|
+
{
|
|
7
|
+
private ObservableCollection<U> _operand;
|
|
8
|
+
private IDisposable _subscriptions;
|
|
9
|
+
|
|
10
|
+
public SelectCollectionObservable(ICollectionObservable<T> source, Func<T, U> select, ObservableCollection<U> operand)
|
|
11
|
+
{
|
|
12
|
+
_operand = operand;
|
|
13
|
+
_subscriptions = source.SubscribeWithId(
|
|
14
|
+
onAdd: (id, value) => operand.Add(id, select(value)),
|
|
15
|
+
onRemove: (id, _) => operand.Remove(id),
|
|
16
|
+
onError: operand.OnError,
|
|
17
|
+
onDispose: Dispose,
|
|
18
|
+
immediate: true
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public void Dispose()
|
|
23
|
+
{
|
|
24
|
+
_subscriptions?.Dispose();
|
|
25
|
+
_subscriptions = null;
|
|
26
|
+
_operand.Dispose();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
29
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
1
|
+
fileFormatVersion: 2
|
|
2
2
|
guid: 7df358d544ba60a4fbaafcaab5597e92
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
|
|
3
|
-
namespace ObserveThing
|
|
4
|
-
{
|
|
5
|
-
public class SelectListObservable<T, U> : IDisposable
|
|
6
|
-
{
|
|
7
|
-
private ObservableList<U> _operand;
|
|
8
|
-
private IDisposable _subscriptions;
|
|
9
|
-
|
|
10
|
-
public SelectListObservable(IListObservable<T> source, Func<T, U> select, ObservableList<U> operand)
|
|
11
|
-
{
|
|
12
|
-
_operand = operand;
|
|
13
|
-
_subscriptions = source.Subscribe(
|
|
14
|
-
onAdd: (index, value) => _operand.Insert(index, select(value)),
|
|
15
|
-
onRemove: (index, _) => _operand.RemoveAt(index),
|
|
16
|
-
onError: _operand.OnError,
|
|
17
|
-
onDispose: Dispose,
|
|
18
|
-
immediate: true
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public void Dispose()
|
|
23
|
-
{
|
|
24
|
-
_subscriptions?.Dispose();
|
|
25
|
-
_subscriptions = null;
|
|
26
|
-
_operand.Dispose();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
using System;
|
|
2
|
+
|
|
3
|
+
namespace ObserveThing
|
|
4
|
+
{
|
|
5
|
+
public class SelectListObservable<T, U> : IDisposable
|
|
6
|
+
{
|
|
7
|
+
private ObservableList<U> _operand;
|
|
8
|
+
private IDisposable _subscriptions;
|
|
9
|
+
|
|
10
|
+
public SelectListObservable(IListObservable<T> source, Func<T, U> select, ObservableList<U> operand)
|
|
11
|
+
{
|
|
12
|
+
_operand = operand;
|
|
13
|
+
_subscriptions = source.Subscribe(
|
|
14
|
+
onAdd: (index, value) => _operand.Insert(index, select(value)),
|
|
15
|
+
onRemove: (index, _) => _operand.RemoveAt(index),
|
|
16
|
+
onError: _operand.OnError,
|
|
17
|
+
onDispose: Dispose,
|
|
18
|
+
immediate: true
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public void Dispose()
|
|
23
|
+
{
|
|
24
|
+
_subscriptions?.Dispose();
|
|
25
|
+
_subscriptions = null;
|
|
26
|
+
_operand.Dispose();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
29
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
1
|
+
fileFormatVersion: 2
|
|
2
2
|
guid: ae1ed197fb8c89245b4831b1a557f91e
|
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Collections.Generic;
|
|
3
|
-
using System.Linq;
|
|
4
|
-
|
|
5
|
-
namespace ObserveThing
|
|
6
|
-
{
|
|
7
|
-
public class SelectManyObservable<T, U> : IDisposable
|
|
8
|
-
{
|
|
9
|
-
private class ElementData
|
|
10
|
-
{
|
|
11
|
-
public IDisposable subscription;
|
|
12
|
-
public Dictionary<uint, uint> elementIds = new Dictionary<uint, uint>();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
private ObservableCollection<U> _operand;
|
|
16
|
-
private Func<T, ICollectionObservable<U>> _select;
|
|
17
|
-
private Dictionary<uint, ElementData> _dataById = new Dictionary<uint, ElementData>();
|
|
18
|
-
private CollectionIdProvider _idProvider;
|
|
19
|
-
private IDisposable _subscriptions;
|
|
20
|
-
|
|
21
|
-
public SelectManyObservable(ICollectionObservable<T> source, Func<T, ICollectionObservable<U>> select, ObservableCollection<U> operand)
|
|
22
|
-
{
|
|
23
|
-
_select = select;
|
|
24
|
-
_operand = operand;
|
|
25
|
-
_idProvider = new CollectionIdProvider(x => _dataById.Values.Any(y => y.elementIds.ContainsKey(x)));
|
|
26
|
-
_subscriptions = source.SubscribeWithId(
|
|
27
|
-
onAdd: HandleAdd,
|
|
28
|
-
onRemove: HandleRemove,
|
|
29
|
-
onError: operand.OnError,
|
|
30
|
-
onDispose: Dispose,
|
|
31
|
-
immediate: true
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private void HandleAdd(uint id, T element)
|
|
36
|
-
{
|
|
37
|
-
var data = new ElementData();
|
|
38
|
-
_dataById.Add(id, data);
|
|
39
|
-
data.subscription = _select(element).SubscribeWithId(
|
|
40
|
-
onAdd: (subId, subElement) =>
|
|
41
|
-
{
|
|
42
|
-
var newId = _idProvider.GetUnusedId();
|
|
43
|
-
data.elementIds.Add(subId, newId);
|
|
44
|
-
_operand.Add(newId, subElement);
|
|
45
|
-
},
|
|
46
|
-
onRemove: (subId, subElement) =>
|
|
47
|
-
{
|
|
48
|
-
var elementId = data.elementIds[subId];
|
|
49
|
-
data.elementIds.Remove(subId);
|
|
50
|
-
_operand.Remove(elementId);
|
|
51
|
-
},
|
|
52
|
-
onError: _operand.OnError,
|
|
53
|
-
immediate: true
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private void HandleRemove(uint id, T element)
|
|
58
|
-
{
|
|
59
|
-
var data = _dataById[id];
|
|
60
|
-
_dataById.Remove(id);
|
|
61
|
-
data.subscription.Dispose();
|
|
62
|
-
|
|
63
|
-
foreach (var elementId in data.elementIds.Values)
|
|
64
|
-
_operand.Remove(elementId);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
public void Dispose()
|
|
68
|
-
{
|
|
69
|
-
_subscriptions?.Dispose();
|
|
70
|
-
_subscriptions = null;
|
|
71
|
-
|
|
72
|
-
foreach (var data in _dataById.Values)
|
|
73
|
-
data.subscription.Dispose();
|
|
74
|
-
|
|
75
|
-
_operand.Dispose();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Linq;
|
|
4
|
+
|
|
5
|
+
namespace ObserveThing
|
|
6
|
+
{
|
|
7
|
+
public class SelectManyObservable<T, U> : IDisposable
|
|
8
|
+
{
|
|
9
|
+
private class ElementData
|
|
10
|
+
{
|
|
11
|
+
public IDisposable subscription;
|
|
12
|
+
public Dictionary<uint, uint> elementIds = new Dictionary<uint, uint>();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
private ObservableCollection<U> _operand;
|
|
16
|
+
private Func<T, ICollectionObservable<U>> _select;
|
|
17
|
+
private Dictionary<uint, ElementData> _dataById = new Dictionary<uint, ElementData>();
|
|
18
|
+
private CollectionIdProvider _idProvider;
|
|
19
|
+
private IDisposable _subscriptions;
|
|
20
|
+
|
|
21
|
+
public SelectManyObservable(ICollectionObservable<T> source, Func<T, ICollectionObservable<U>> select, ObservableCollection<U> operand)
|
|
22
|
+
{
|
|
23
|
+
_select = select;
|
|
24
|
+
_operand = operand;
|
|
25
|
+
_idProvider = new CollectionIdProvider(x => _dataById.Values.Any(y => y.elementIds.ContainsKey(x)));
|
|
26
|
+
_subscriptions = source.SubscribeWithId(
|
|
27
|
+
onAdd: HandleAdd,
|
|
28
|
+
onRemove: HandleRemove,
|
|
29
|
+
onError: operand.OnError,
|
|
30
|
+
onDispose: Dispose,
|
|
31
|
+
immediate: true
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private void HandleAdd(uint id, T element)
|
|
36
|
+
{
|
|
37
|
+
var data = new ElementData();
|
|
38
|
+
_dataById.Add(id, data);
|
|
39
|
+
data.subscription = _select(element).SubscribeWithId(
|
|
40
|
+
onAdd: (subId, subElement) =>
|
|
41
|
+
{
|
|
42
|
+
var newId = _idProvider.GetUnusedId();
|
|
43
|
+
data.elementIds.Add(subId, newId);
|
|
44
|
+
_operand.Add(newId, subElement);
|
|
45
|
+
},
|
|
46
|
+
onRemove: (subId, subElement) =>
|
|
47
|
+
{
|
|
48
|
+
var elementId = data.elementIds[subId];
|
|
49
|
+
data.elementIds.Remove(subId);
|
|
50
|
+
_operand.Remove(elementId);
|
|
51
|
+
},
|
|
52
|
+
onError: _operand.OnError,
|
|
53
|
+
immediate: true
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private void HandleRemove(uint id, T element)
|
|
58
|
+
{
|
|
59
|
+
var data = _dataById[id];
|
|
60
|
+
_dataById.Remove(id);
|
|
61
|
+
data.subscription.Dispose();
|
|
62
|
+
|
|
63
|
+
foreach (var elementId in data.elementIds.Values)
|
|
64
|
+
_operand.Remove(elementId);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public void Dispose()
|
|
68
|
+
{
|
|
69
|
+
_subscriptions?.Dispose();
|
|
70
|
+
_subscriptions = null;
|
|
71
|
+
|
|
72
|
+
foreach (var data in _dataById.Values)
|
|
73
|
+
data.subscription.Dispose();
|
|
74
|
+
|
|
75
|
+
_operand.Dispose();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
78
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
1
|
+
fileFormatVersion: 2
|
|
2
2
|
guid: f886cc5c9646e3e4683026dfb1b413e2
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
|
|
3
|
-
namespace ObserveThing
|
|
4
|
-
{
|
|
5
|
-
public class SelectValueOperator<T, U> : IDisposable
|
|
6
|
-
{
|
|
7
|
-
private ObservableValue<U> _operand;
|
|
8
|
-
private IDisposable _subscriptions;
|
|
9
|
-
|
|
10
|
-
public SelectValueOperator(IValueObservable<T> source, Func<T, U> select, ObservableValue<U> operand)
|
|
11
|
-
{
|
|
12
|
-
_operand = operand;
|
|
13
|
-
_subscriptions = source.Subscribe(
|
|
14
|
-
onNext: x => operand.value = select(x),
|
|
15
|
-
onError: operand.OnError,
|
|
16
|
-
onDispose: operand.Dispose,
|
|
17
|
-
immediate: true
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public void Dispose()
|
|
22
|
-
{
|
|
23
|
-
_subscriptions?.Dispose();
|
|
24
|
-
_subscriptions = null;
|
|
25
|
-
_operand.Dispose();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
using System;
|
|
2
|
+
|
|
3
|
+
namespace ObserveThing
|
|
4
|
+
{
|
|
5
|
+
public class SelectValueOperator<T, U> : IDisposable
|
|
6
|
+
{
|
|
7
|
+
private ObservableValue<U> _operand;
|
|
8
|
+
private IDisposable _subscriptions;
|
|
9
|
+
|
|
10
|
+
public SelectValueOperator(IValueObservable<T> source, Func<T, U> select, ObservableValue<U> operand)
|
|
11
|
+
{
|
|
12
|
+
_operand = operand;
|
|
13
|
+
_subscriptions = source.Subscribe(
|
|
14
|
+
onNext: x => operand.value = select(x),
|
|
15
|
+
onError: operand.OnError,
|
|
16
|
+
onDispose: operand.Dispose,
|
|
17
|
+
immediate: true
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public void Dispose()
|
|
22
|
+
{
|
|
23
|
+
_subscriptions?.Dispose();
|
|
24
|
+
_subscriptions = null;
|
|
25
|
+
_operand.Dispose();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
28
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
1
|
+
fileFormatVersion: 2
|
|
2
2
|
guid: 11e1e51b831c1e34abed3453cd15be99
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
|
|
3
|
-
namespace ObserveThing
|
|
4
|
-
{
|
|
5
|
-
public class SkipWhileObservable<T> : IDisposable
|
|
6
|
-
{
|
|
7
|
-
private ObservableValue<T> _operand;
|
|
8
|
-
private IDisposable _subscriptions;
|
|
9
|
-
|
|
10
|
-
public SkipWhileObservable(IValueObservable<T> source, Func<bool> skipWhile, ObservableValue<T> operand)
|
|
11
|
-
{
|
|
12
|
-
_operand = operand;
|
|
13
|
-
_subscriptions = source.Subscribe(
|
|
14
|
-
onNext: value =>
|
|
15
|
-
{
|
|
16
|
-
if (!skipWhile())
|
|
17
|
-
_operand.value = value;
|
|
18
|
-
},
|
|
19
|
-
onError: _operand.OnError,
|
|
20
|
-
onDispose: Dispose,
|
|
21
|
-
immediate: true
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public void Dispose()
|
|
26
|
-
{
|
|
27
|
-
_subscriptions?.Dispose();
|
|
28
|
-
_subscriptions = null;
|
|
29
|
-
_operand.Dispose();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
using System;
|
|
2
|
+
|
|
3
|
+
namespace ObserveThing
|
|
4
|
+
{
|
|
5
|
+
public class SkipWhileObservable<T> : IDisposable
|
|
6
|
+
{
|
|
7
|
+
private ObservableValue<T> _operand;
|
|
8
|
+
private IDisposable _subscriptions;
|
|
9
|
+
|
|
10
|
+
public SkipWhileObservable(IValueObservable<T> source, Func<bool> skipWhile, ObservableValue<T> operand)
|
|
11
|
+
{
|
|
12
|
+
_operand = operand;
|
|
13
|
+
_subscriptions = source.Subscribe(
|
|
14
|
+
onNext: value =>
|
|
15
|
+
{
|
|
16
|
+
if (!skipWhile())
|
|
17
|
+
_operand.value = value;
|
|
18
|
+
},
|
|
19
|
+
onError: _operand.OnError,
|
|
20
|
+
onDispose: Dispose,
|
|
21
|
+
immediate: true
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public void Dispose()
|
|
26
|
+
{
|
|
27
|
+
_subscriptions?.Dispose();
|
|
28
|
+
_subscriptions = null;
|
|
29
|
+
_operand.Dispose();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
32
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
fileFormatVersion: 2
|
|
1
|
+
fileFormatVersion: 2
|
|
2
2
|
guid: 7827b68ec45cef44992f41375a48de42
|