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.
- package/README.md +2 -0
- package/README.md.meta +7 -0
- package/Runtime/CollectionIdProvider.cs +72 -0
- package/Runtime/CollectionIdProvider.cs.meta +2 -0
- package/Runtime/IObservable.cs +66 -0
- package/Runtime/IObservable.cs.meta +2 -0
- package/Runtime/Implementations/Observable.cs +30 -0
- package/Runtime/Implementations/Observable.cs.meta +2 -0
- package/Runtime/Implementations/ObservableBase.cs +173 -0
- package/Runtime/Implementations/ObservableBase.cs.meta +2 -0
- package/Runtime/Implementations/ObservableCollection.cs +141 -0
- package/Runtime/Implementations/ObservableCollection.cs.meta +2 -0
- package/Runtime/Implementations/ObservableDictionary.cs +166 -0
- package/Runtime/Implementations/ObservableDictionary.cs.meta +2 -0
- package/Runtime/Implementations/ObservableList.cs +163 -0
- package/Runtime/Implementations/ObservableList.cs.meta +2 -0
- package/Runtime/Implementations/ObservableSet.cs +137 -0
- package/Runtime/Implementations/ObservableSet.cs.meta +2 -0
- package/Runtime/Implementations/ObservableValue.cs +59 -0
- package/Runtime/Implementations/ObservableValue.cs.meta +2 -0
- package/Runtime/Implementations.meta +8 -0
- package/Runtime/Observables/BatchObservable.cs +72 -0
- package/Runtime/Observables/BatchObservable.cs.meta +2 -0
- package/Runtime/Observables/CastObservable.cs +128 -0
- package/Runtime/Observables/CastObservable.cs.meta +2 -0
- package/Runtime/Observables/CombineObservable.cs +96 -0
- package/Runtime/Observables/CombineObservable.cs.meta +2 -0
- package/Runtime/Observables/CombineValueObservable.cs +319 -0
- package/Runtime/Observables/CombineValueObservable.cs.meta +2 -0
- package/Runtime/Observables/ConcatObservable.cs +75 -0
- package/Runtime/Observables/ConcatObservable.cs.meta +2 -0
- package/Runtime/Observables/ContainsObservable.cs +71 -0
- package/Runtime/Observables/ContainsObservable.cs.meta +2 -0
- package/Runtime/Observables/CountObservable.cs +29 -0
- package/Runtime/Observables/CountObservable.cs.meta +2 -0
- package/Runtime/Observables/DistinctObservable.cs +55 -0
- package/Runtime/Observables/DistinctObservable.cs.meta +2 -0
- package/Runtime/Observables/FirstObservable.cs +53 -0
- package/Runtime/Observables/FirstObservable.cs.meta +2 -0
- package/Runtime/Observables/IndexOfObservable.cs +83 -0
- package/Runtime/Observables/IndexOfObservable.cs.meta +2 -0
- package/Runtime/Observables/OperationStreamObservable.cs +194 -0
- package/Runtime/Observables/OperationStreamObservable.cs.meta +2 -0
- package/Runtime/Observables/OrderByObservable.cs +116 -0
- package/Runtime/Observables/OrderByObservable.cs.meta +2 -0
- package/Runtime/Observables/SelectCollectionObservable.cs +29 -0
- package/Runtime/Observables/SelectCollectionObservable.cs.meta +2 -0
- package/Runtime/Observables/SelectListObservable.cs +29 -0
- package/Runtime/Observables/SelectListObservable.cs.meta +2 -0
- package/Runtime/Observables/SelectManyObservable.cs +78 -0
- package/Runtime/Observables/SelectManyObservable.cs.meta +2 -0
- package/Runtime/Observables/SelectValueObservable.cs +28 -0
- package/Runtime/Observables/SelectValueObservable.cs.meta +2 -0
- package/Runtime/Observables/SkipWhileObservable.cs +32 -0
- package/Runtime/Observables/SkipWhileObservable.cs.meta +2 -0
- package/Runtime/Observables/ThenObservable.cs +209 -0
- package/Runtime/Observables/ThenObservable.cs.meta +2 -0
- package/Runtime/Observables/ToDictionaryObservable.cs +35 -0
- package/Runtime/Observables/ToDictionaryObservable.cs.meta +2 -0
- package/Runtime/Observables/TrackObservable.cs +74 -0
- package/Runtime/Observables/TrackObservable.cs.meta +2 -0
- package/Runtime/Observables/UnwrapCollectionObservable.cs +64 -0
- package/Runtime/Observables/UnwrapCollectionObservable.cs.meta +2 -0
- package/Runtime/Observables/UnwrapListObservable.cs +69 -0
- package/Runtime/Observables/UnwrapListObservable.cs.meta +2 -0
- package/Runtime/Observables/UnwrapValueObservable.cs +56 -0
- package/Runtime/Observables/UnwrapValueObservable.cs.meta +2 -0
- package/Runtime/Observables/WhereObservable.cs +85 -0
- package/Runtime/Observables/WhereObservable.cs.meta +2 -0
- package/Runtime/Observables/WithPreviousObservable.cs +36 -0
- package/Runtime/Observables/WithPreviousObservable.cs.meta +2 -0
- package/Runtime/Observables.cs +467 -0
- package/Runtime/Observables.cs.meta +2 -0
- package/Runtime/Observables.meta +8 -0
- package/Runtime/ObservationContext.cs +126 -0
- package/Runtime/ObservationContext.cs.meta +2 -0
- package/Runtime/Observers.cs +403 -0
- package/Runtime/Observers.cs.meta +2 -0
- package/Runtime/Operators/BatchOperator.cs +71 -0
- package/Runtime/Operators/BatchOperator.cs.meta +2 -0
- package/Runtime/Operators/CollectionOperator.cs +30 -0
- package/Runtime/Operators/CollectionOperator.cs.meta +2 -0
- package/Runtime/Operators/DictionaryOperator.cs +45 -0
- package/Runtime/Operators/DictionaryOperator.cs.meta +2 -0
- package/Runtime/Operators/IInitializationOperationsProvider.cs +10 -0
- package/Runtime/Operators/IInitializationOperationsProvider.cs.meta +2 -0
- package/Runtime/Operators/ListOperator.cs +44 -0
- package/Runtime/Operators/ListOperator.cs.meta +2 -0
- package/Runtime/Operators/ObservableOperator.cs +75 -0
- package/Runtime/Operators/ObservableOperator.cs.meta +2 -0
- package/Runtime/Operators/Operator.cs +65 -0
- package/Runtime/Operators/Operator.cs.meta +2 -0
- package/Runtime/Operators/SetOperator.cs +44 -0
- package/Runtime/Operators/SetOperator.cs.meta +2 -0
- package/Runtime/Operators/ValueOperator.cs +30 -0
- package/Runtime/Operators/ValueOperator.cs.meta +2 -0
- package/Runtime/Operators.meta +8 -0
- package/Runtime/PriorityQueue.cs +1096 -0
- package/Runtime/PriorityQueue.cs.meta +2 -0
- package/Runtime/com.fofx.observething.asmdef +14 -0
- package/Runtime/com.fofx.observething.asmdef.meta +7 -0
- package/Runtime.meta +8 -0
- package/Tests/CollectionObservableTests.cs +739 -0
- package/Tests/CollectionObservableTests.cs.meta +2 -0
- package/Tests/DictionaryObservableTests.cs +85 -0
- package/Tests/DictionaryObservableTests.cs.meta +2 -0
- package/Tests/ListObservableTests.cs +148 -0
- package/Tests/ListObservableTests.cs.meta +2 -0
- package/Tests/ObservationContextTests.cs +359 -0
- package/Tests/ObservationContextTests.cs.meta +2 -0
- package/Tests/ValueObservableTests.cs +322 -0
- package/Tests/ValueObservableTests.cs.meta +2 -0
- package/Tests/com.fofx.observething.tests.asmdef +24 -0
- package/Tests/com.fofx.observething.tests.asmdef.meta +7 -0
- package/Tests.meta +8 -0
- package/package.json +24 -0
- package/package.json.meta +7 -0
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
|
|
4
|
+
namespace ObserveThing
|
|
5
|
+
{
|
|
6
|
+
public static class Observables
|
|
7
|
+
{
|
|
8
|
+
public static IValueObservable<T> ObservableCast<T>(this IValueObservable source)
|
|
9
|
+
=> new ValueOperator<T>(source.context, operand => new CastValueObservable<T>(source, operand));
|
|
10
|
+
|
|
11
|
+
public static ICollectionObservable<T> ObservableCast<T>(this ICollectionObservable source)
|
|
12
|
+
=> new CollectionOperator<T>(source.context, operand => new CastCollectionObservable<T>(source, operand));
|
|
13
|
+
|
|
14
|
+
public static IListObservable<T> ObservableCast<T>(this IListObservable source)
|
|
15
|
+
=> new ListOperator<T>(source.context, operand => new CastListObservable<T>(source, operand));
|
|
16
|
+
|
|
17
|
+
public static ISetObservable<T> ObservableCast<T>(this ISetObservable source)
|
|
18
|
+
=> new SetOperator<T>(source.context, operand => new CastSetObservable<T>(source, operand));
|
|
19
|
+
|
|
20
|
+
public static IDictionaryObservable<TKey, TValue> ObservableCast<TKey, TValue>(this IDictionaryObservable source)
|
|
21
|
+
=> new DictionaryOperator<TKey, TValue>(source.context, operand => new CastDictionaryObservable<TKey, TValue>(source, operand));
|
|
22
|
+
|
|
23
|
+
public static IObservable<ValueOp<T>> ObservableOperationStream<T>(this IValueObservable<T> source)
|
|
24
|
+
=> new ObservableOperator<ValueOp<T>>(source.context, operand => new ValueOperationStreamObservable<T>(source, operand));
|
|
25
|
+
|
|
26
|
+
public static IObservable<CollectionOp<T>> ObservableOperationStream<T>(this ICollectionObservable<T> source)
|
|
27
|
+
=> new ObservableOperator<CollectionOp<T>>(source.context, operand => new CollectionOperationStreamObservable<T>(source, operand));
|
|
28
|
+
|
|
29
|
+
public static IObservable<ListOp<T>> ObservableOperationStream<T>(this IListObservable<T> source)
|
|
30
|
+
=> new ObservableOperator<ListOp<T>>(source.context, operand => new ListOperationStreamObservable<T>(source, operand));
|
|
31
|
+
|
|
32
|
+
public static IObservable<DictionaryOp<TKey, TValue>> ObservableOperationStream<TKey, TValue>(this IDictionaryObservable<TKey, TValue> source)
|
|
33
|
+
=> new ObservableOperator<DictionaryOp<TKey, TValue>>(source.context, operand => new DictionaryOperationStreamObservable<TKey, TValue>(source, operand));
|
|
34
|
+
|
|
35
|
+
public static IObservable<SetOp<T>> ObservableOperationStream<T>(this ISetObservable<T> source)
|
|
36
|
+
=> new ObservableOperator<SetOp<T>>(source.context, operand => new SetOperationStreamObservable<T>(source, operand));
|
|
37
|
+
|
|
38
|
+
public static IObservable<BatchOp<ValueOp<T>>> ObservableBatch<T>(this IValueObservable<T> source)
|
|
39
|
+
=> source.ObservableOperationStream().ObservableBatch();
|
|
40
|
+
|
|
41
|
+
public static IObservable<BatchOp<CollectionOp<T>>> ObservableBatch<T>(this ICollectionObservable<T> source)
|
|
42
|
+
=> source.ObservableOperationStream().ObservableBatch();
|
|
43
|
+
|
|
44
|
+
public static IObservable<BatchOp<ListOp<T>>> ObservableBatch<T>(this IListObservable<T> source)
|
|
45
|
+
=> source.ObservableOperationStream().ObservableBatch();
|
|
46
|
+
|
|
47
|
+
public static IObservable<BatchOp<DictionaryOp<TKey, TValue>>> ObservableBatch<TKey, TValue>(this IDictionaryObservable<TKey, TValue> source)
|
|
48
|
+
=> source.ObservableOperationStream().ObservableBatch();
|
|
49
|
+
|
|
50
|
+
public static IObservable<BatchOp<SetOp<T>>> ObservableBatch<T>(this ISetObservable<T> source)
|
|
51
|
+
=> source.ObservableOperationStream().ObservableBatch();
|
|
52
|
+
|
|
53
|
+
public static IObservable<BatchOp<T>> ObservableBatch<T>(this IObservable<T> source) where T : IOperation
|
|
54
|
+
=> new ObservableOperator<BatchOp<T>>(source.context, operand => new BatchObservable<T>(source, operand));
|
|
55
|
+
|
|
56
|
+
public static IObservable<T> ObservableCombine<T>(this ISetObservable<IObservable<T>> source, bool disposeOnSourceEmpty = true) where T : IOperation
|
|
57
|
+
=> new ObservableOperator<T>(source.context, operand => new CombineObservable<T>(source, operand, disposeOnSourceEmpty));
|
|
58
|
+
|
|
59
|
+
public static IObservable<T> ObservableCombine<T>(params IObservable<T>[] observables) where T : IOperation
|
|
60
|
+
=> new ObservableSet<IObservable<T>>(observables[0].context, observables).ObservableCombine(disposeOnSourceEmpty: true);
|
|
61
|
+
|
|
62
|
+
public static IObservable<T> ObservableCombine<T>(bool disposeOnSourceEmpty, params IObservable<T>[] observables) where T : IOperation
|
|
63
|
+
=> new ObservableSet<IObservable<T>>(observables[0].context, observables).ObservableCombine(disposeOnSourceEmpty: disposeOnSourceEmpty);
|
|
64
|
+
|
|
65
|
+
public static IValueObservable<T> ObservableThen<T>(this IValueObservable<T> source, IValueObserver<T> thenObserver)
|
|
66
|
+
=> new ValueOperator<T>(source.context, operand => new ThenValueObservable<T>(source, thenObserver, operand));
|
|
67
|
+
|
|
68
|
+
public static IValueObservable<T> ObservableThen<T>(this IValueObservable<T> source, Action<T> onNext = default, Action onDispose = default, Action<Exception> onError = default)
|
|
69
|
+
=> source.ObservableThen(new ValueObserver<T>(onNext, onDispose, onError));
|
|
70
|
+
|
|
71
|
+
public static ICollectionObservable<T> ObservableThen<T>(this ICollectionObservable<T> source, ICollectionObserver<T> thenObserver)
|
|
72
|
+
=> new CollectionOperator<T>(source.context, operand => new ThenCollectionObservable<T>(source, thenObserver, operand));
|
|
73
|
+
|
|
74
|
+
public static ICollectionObservable<T> ObservableThen<T>(this ICollectionObservable<T> source, Action<T> onAdd = default, Action<T> onRemove = default, Action onDispose = default, Action<Exception> onError = default)
|
|
75
|
+
=> source.ObservableThen(new CollectionObserver<T>((id, x) => onAdd?.Invoke(x), (id, x) => onRemove?.Invoke(x), onDispose, onError));
|
|
76
|
+
|
|
77
|
+
public static IListObservable<T> ObservableThen<T>(this IListObservable<T> source, IListObserver<T> thenObserver)
|
|
78
|
+
=> new ListOperator<T>(source.context, operand => new ThenListObservable<T>(source, thenObserver, operand));
|
|
79
|
+
|
|
80
|
+
public static IListObservable<T> ObservableThen<T>(this IListObservable<T> source, Action<int, T> onAdd = default, Action<int, T> onRemove = default, Action onDispose = default, Action<Exception> onError = default)
|
|
81
|
+
=> source.ObservableThen(new ListObserver<T>((id, index, x) => onAdd?.Invoke(index, x), (id, index, x) => onRemove?.Invoke(index, x), onDispose, onError));
|
|
82
|
+
|
|
83
|
+
public static ISetObservable<T> ObservableThen<T>(this ISetObservable<T> source, ISetObserver<T> thenObserver)
|
|
84
|
+
=> new SetOperator<T>(source.context, operand => new ThenSetObservable<T>(source, thenObserver, operand));
|
|
85
|
+
|
|
86
|
+
public static ISetObservable<T> ObservableThen<T>(this ISetObservable<T> source, Action<T> onAdd = default, Action<T> onRemove = default, Action onDispose = default, Action<Exception> onError = default)
|
|
87
|
+
=> source.ObservableThen(new SetObserver<T>((id, x) => onAdd?.Invoke(x), (id, x) => onRemove?.Invoke(x), onDispose, onError));
|
|
88
|
+
|
|
89
|
+
public static IDictionaryObservable<TKey, TValue> ObservableThen<TKey, TValue>(this IDictionaryObservable<TKey, TValue> source, IDictionaryObserver<TKey, TValue> thenObserver)
|
|
90
|
+
=> new DictionaryOperator<TKey, TValue>(source.context, operand => new ThenDictionaryObservable<TKey, TValue>(source, thenObserver, operand));
|
|
91
|
+
|
|
92
|
+
public static IDictionaryObservable<TKey, TValue> ObservableThen<TKey, TValue>(this IDictionaryObservable<TKey, TValue> source, Action<KeyValuePair<TKey, TValue>> onAdd = default, Action<KeyValuePair<TKey, TValue>> onRemove = default, Action onDispose = default, Action<Exception> onError = default)
|
|
93
|
+
=> source.ObservableThen(new DictionaryObserver<TKey, TValue>((id, x) => onAdd?.Invoke(x), (id, x) => onRemove?.Invoke(x), onDispose, onError));
|
|
94
|
+
|
|
95
|
+
public static IValueObservable<(T1, T2)> ObservableCombineValues<T1, T2>(IValueObservable<T1> source1, IValueObservable<T2> source2)
|
|
96
|
+
=> new ValueOperator<(T1, T2)>(source1.context, operand => new CombineValueObservable<T1, T2>(source1, source2, operand));
|
|
97
|
+
|
|
98
|
+
public static IValueObservable<TResult> ObservableCombineValues<T1, T2, TResult>(IValueObservable<T1> source1, IValueObservable<T2> source2, Func<T1, T2, IValueObservable<TResult>> select)
|
|
99
|
+
=> ObservableCombineValues(source1, source2).ObservableSelect(x => select(x.Item1, x.Item2));
|
|
100
|
+
|
|
101
|
+
public static IValueObservable<TResult> ObservableCombineValues<T1, T2, TResult>(IValueObservable<T1> source1, IValueObservable<T2> source2, Func<T1, T2, TResult> select)
|
|
102
|
+
=> ObservableCombineValues(source1, source2).ObservableSelect(x => select(x.Item1, x.Item2));
|
|
103
|
+
|
|
104
|
+
public static IValueObservable<(T1, T2, T3)> ObservableCombineValues<T1, T2, T3>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3)
|
|
105
|
+
=> new ValueOperator<(T1, T2, T3)>(source1.context, operand => new CombineValueObservable<T1, T2, T3>(source1, source2, source3, operand));
|
|
106
|
+
|
|
107
|
+
public static IValueObservable<TResult> ObservableCombineValues<T1, T2, T3, TResult>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, Func<T1, T2, T3, IValueObservable<TResult>> select)
|
|
108
|
+
=> ObservableCombineValues(source1, source2, source3).ObservableSelect(x => select(x.Item1, x.Item2, x.Item3));
|
|
109
|
+
|
|
110
|
+
public static IValueObservable<TResult> ObservableCombineValues<T1, T2, T3, TResult>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, Func<T1, T2, T3, TResult> select)
|
|
111
|
+
=> ObservableCombineValues(source1, source2, source3).ObservableSelect(x => select(x.Item1, x.Item2, x.Item3));
|
|
112
|
+
|
|
113
|
+
public static IValueObservable<(T1, T2, T3, T4)> ObservableCombineValues<T1, T2, T3, T4>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, IValueObservable<T4> source4)
|
|
114
|
+
=> new ValueOperator<(T1, T2, T3, T4)>(source1.context, operand => new CombineValueObservable<T1, T2, T3, T4>(source1, source2, source3, source4, operand));
|
|
115
|
+
|
|
116
|
+
public static IValueObservable<TResult> ObservableCombineValues<T1, T2, T3, T4, TResult>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, IValueObservable<T4> source4, Func<T1, T2, T3, T4, IValueObservable<TResult>> select)
|
|
117
|
+
=> ObservableCombineValues(source1, source2, source3, source4).ObservableSelect(x => select(x.Item1, x.Item2, x.Item3, x.Item4));
|
|
118
|
+
|
|
119
|
+
public static IValueObservable<TResult> ObservableCombineValues<T1, T2, T3, T4, TResult>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, IValueObservable<T4> source4, Func<T1, T2, T3, T4, TResult> select)
|
|
120
|
+
=> ObservableCombineValues(source1, source2, source3, source4).ObservableSelect(x => select(x.Item1, x.Item2, x.Item3, x.Item4));
|
|
121
|
+
|
|
122
|
+
public static IValueObservable<(T1, T2, T3, T4, T5)> ObservableCombineValues<T1, T2, T3, T4, T5>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, IValueObservable<T4> source4, IValueObservable<T5> source5)
|
|
123
|
+
=> new ValueOperator<(T1, T2, T3, T4, T5)>(source1.context, operand => new CombineValueObservable<T1, T2, T3, T4, T5>(source1, source2, source3, source4, source5, operand));
|
|
124
|
+
|
|
125
|
+
public static IValueObservable<TResult> ObservableCombineValues<T1, T2, T3, T4, T5, TResult>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, IValueObservable<T4> source4, IValueObservable<T5> source5, Func<T1, T2, T3, T4, T5, IValueObservable<TResult>> select)
|
|
126
|
+
=> ObservableCombineValues(source1, source2, source3, source4, source5).ObservableSelect(x => select(x.Item1, x.Item2, x.Item3, x.Item4, x.Item5));
|
|
127
|
+
|
|
128
|
+
public static IValueObservable<TResult> ObservableCombineValues<T1, T2, T3, T4, T5, TResult>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, IValueObservable<T4> source4, IValueObservable<T5> source5, Func<T1, T2, T3, T4, T5, TResult> select)
|
|
129
|
+
=> ObservableCombineValues(source1, source2, source3, source4, source5).ObservableSelect(x => select(x.Item1, x.Item2, x.Item3, x.Item4, x.Item5));
|
|
130
|
+
|
|
131
|
+
public static IValueObservable<(T1, T2, T3, T4, T5, T6)> ObservableCombineValues<T1, T2, T3, T4, T5, T6>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, IValueObservable<T4> source4, IValueObservable<T5> source5, IValueObservable<T6> source6)
|
|
132
|
+
=> new ValueOperator<(T1, T2, T3, T4, T5, T6)>(source1.context, operand => new CombineValueObservable<T1, T2, T3, T4, T5, T6>(source1, source2, source3, source4, source5, source6, operand));
|
|
133
|
+
|
|
134
|
+
public static IValueObservable<TResult> ObservableCombineValues<T1, T2, T3, T4, T5, T6, TResult>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, IValueObservable<T4> source4, IValueObservable<T5> source5, IValueObservable<T6> source6, Func<T1, T2, T3, T4, T5, T6, IValueObservable<TResult>> select)
|
|
135
|
+
=> ObservableCombineValues(source1, source2, source3, source4, source5, source6).ObservableSelect(x => select(x.Item1, x.Item2, x.Item3, x.Item4, x.Item5, x.Item6));
|
|
136
|
+
|
|
137
|
+
public static IValueObservable<TResult> ObservableCombineValues<T1, T2, T3, T4, T5, T6, TResult>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, IValueObservable<T4> source4, IValueObservable<T5> source5, IValueObservable<T6> source6, Func<T1, T2, T3, T4, T5, T6, TResult> select)
|
|
138
|
+
=> ObservableCombineValues(source1, source2, source3, source4, source5, source6).ObservableSelect(x => select(x.Item1, x.Item2, x.Item3, x.Item4, x.Item5, x.Item6));
|
|
139
|
+
|
|
140
|
+
public static IValueObservable<(T1, T2, T3, T4, T5, T6, T7)> ObservableCombineValues<T1, T2, T3, T4, T5, T6, T7>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, IValueObservable<T4> source4, IValueObservable<T5> source5, IValueObservable<T6> source6, IValueObservable<T7> source7)
|
|
141
|
+
=> new ValueOperator<(T1, T2, T3, T4, T5, T6, T7)>(source1.context, operand => new CombineValueObservable<T1, T2, T3, T4, T5, T6, T7>(source1, source2, source3, source4, source5, source6, source7, operand));
|
|
142
|
+
|
|
143
|
+
public static IValueObservable<TResult> ObservableCombineValues<T1, T2, T3, T4, T5, T6, T7, TResult>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, IValueObservable<T4> source4, IValueObservable<T5> source5, IValueObservable<T6> source6, IValueObservable<T7> source7, Func<T1, T2, T3, T4, T5, T6, T7, IValueObservable<TResult>> select)
|
|
144
|
+
=> ObservableCombineValues(source1, source2, source3, source4, source5, source6, source7).ObservableSelect(x => select(x.Item1, x.Item2, x.Item3, x.Item4, x.Item5, x.Item6, x.Item7));
|
|
145
|
+
|
|
146
|
+
public static IValueObservable<TResult> ObservableCombineValues<T1, T2, T3, T4, T5, T6, T7, TResult>(IValueObservable<T1> source1, IValueObservable<T2> source2, IValueObservable<T3> source3, IValueObservable<T4> source4, IValueObservable<T5> source5, IValueObservable<T6> source6, IValueObservable<T7> source7, Func<T1, T2, T3, T4, T5, T6, T7, TResult> select)
|
|
147
|
+
=> ObservableCombineValues(source1, source2, source3, source4, source5, source6, source7).ObservableSelect(x => select(x.Item1, x.Item2, x.Item3, x.Item4, x.Item5, x.Item6, x.Item7));
|
|
148
|
+
|
|
149
|
+
public static IValueObservable<T> ObservableUnwrap<T>(this IValueObservable<IValueObservable<T>> source)
|
|
150
|
+
=> new ValueOperator<T>(source.context, operand => new UnwrapValueObservable<T>(source, operand));
|
|
151
|
+
|
|
152
|
+
public static IValueObservable<U> ObservableSelect<T, U>(this IValueObservable<T> source, Func<T, U> select)
|
|
153
|
+
=> new ValueOperator<U>(source.context, operand => new SelectValueOperator<T, U>(source, select, operand));
|
|
154
|
+
|
|
155
|
+
public static IValueObservable<U> ObservableSelect<T, U>(this IValueObservable<T> source, Func<T, IValueObservable<U>> select)
|
|
156
|
+
=> source.ObservableSelect<T, IValueObservable<U>>(select).ObservableUnwrap();
|
|
157
|
+
|
|
158
|
+
public static IValueObservable<(T current, T previous)> ObservableWithPrevious<T>(this IValueObservable<T> source)
|
|
159
|
+
=> new ValueOperator<(T current, T previous)>(source.context, operand => new WithPreviousObservable<T>(source, operand));
|
|
160
|
+
|
|
161
|
+
public static IValueObservable<T> ObservableSkipWhile<T>(this IValueObservable<T> source, Func<bool> skipWhile)
|
|
162
|
+
=> new ValueOperator<T>(source.context, operand => new SkipWhileObservable<T>(source, skipWhile, operand));
|
|
163
|
+
|
|
164
|
+
public static ICollectionObservable<T> ObservableUnwrap<T>(this ICollectionObservable<IValueObservable<T>> source)
|
|
165
|
+
=> new CollectionOperator<T>(source.context, operand => new UnwrapCollectionObservable<T>(source, operand));
|
|
166
|
+
|
|
167
|
+
public static ICollectionObservable<U> ObservableSelect<T, U>(this ICollectionObservable<T> source, Func<T, IValueObservable<U>> select)
|
|
168
|
+
=> source.ObservableSelect<T, IValueObservable<U>>(select).ObservableUnwrap();
|
|
169
|
+
|
|
170
|
+
public static ICollectionObservable<U> ObservableSelect<T, U>(this ICollectionObservable<T> source, Func<T, U> select)
|
|
171
|
+
=> new CollectionOperator<U>(source.context, operand => new SelectCollectionObservable<T, U>(source, select, operand));
|
|
172
|
+
|
|
173
|
+
public static ISetObservable<T> ObservableDistinct<T>(this ICollectionObservable<T> source)
|
|
174
|
+
=> new SetOperator<T>(source.context, operand => new DistinctObservable<T>(source, operand));
|
|
175
|
+
|
|
176
|
+
public static ICollectionObservable<T> ObservableWhere<T>(this ICollectionObservable<T> source, Func<T, bool> where)
|
|
177
|
+
=> source.ObservableWhere(x => new ObservableValue<bool>(source.context, where(x)));
|
|
178
|
+
|
|
179
|
+
public static ICollectionObservable<T> ObservableWhere<T>(this ICollectionObservable<T> source, Func<T, IValueObservable<bool>> where)
|
|
180
|
+
=> new CollectionOperator<T>(source.context, operand => new WhereObservable<T>(source, where, operand));
|
|
181
|
+
|
|
182
|
+
public static ICollectionObservable<T> ObservableConcat<T>(this ICollectionObservable<T> source1, IEnumerable<T> source2)
|
|
183
|
+
=> source1.ObservableConcat((ICollectionObservable<T>)new ObservableCollection<T>(source1.context, source2));
|
|
184
|
+
|
|
185
|
+
public static ICollectionObservable<T> ObservableConcat<T>(this ICollectionObservable<T> source1, ICollectionObservable<T> source2)
|
|
186
|
+
=> new CollectionOperator<T>(source1.context, operand => new ConcatObservable<T>(source1, source2, operand));
|
|
187
|
+
|
|
188
|
+
public static ICollectionObservable<U> ObservableSelectMany<T, U>(this ICollectionObservable<T> source, Func<T, IEnumerable<U>> selectMany)
|
|
189
|
+
=> source.ObservableSelectMany(x => (ICollectionObservable<U>)new ObservableCollection<U>(source.context, selectMany(x)));
|
|
190
|
+
|
|
191
|
+
public static ICollectionObservable<U> ObservableSelectMany<T, U>(this ICollectionObservable<T> source, Func<T, ICollectionObservable<U>> selectMany)
|
|
192
|
+
=> new CollectionOperator<U>(source.context, operand => new SelectManyObservable<T, U>(source, selectMany, operand));
|
|
193
|
+
|
|
194
|
+
public static IListObservable<T> ObservableOrderBy<T, U>(this ICollectionObservable<T> source, Func<T, U> orderBy)
|
|
195
|
+
=> source.ObservableOrderBy<T, U>(x => new ObservableValue<U>(source.context, orderBy(x)));
|
|
196
|
+
|
|
197
|
+
public static IListObservable<T> ObservableOrderBy<T, U>(this ICollectionObservable<T> source, Func<T, IValueObservable<U>> orderBy)
|
|
198
|
+
=> new ListOperator<T>(source.context, operand => new OrderByObservable<T, U>(source, orderBy, false, operand));
|
|
199
|
+
|
|
200
|
+
public static IListObservable<T> ObservableOrderByDescending<T, U>(this ICollectionObservable<T> source, Func<T, U> orderBy)
|
|
201
|
+
=> source.ObservableOrderByDescending<T, U>(x => new ObservableValue<U>(source.context, orderBy(x)));
|
|
202
|
+
|
|
203
|
+
public static IListObservable<T> ObservableOrderByDescending<T, U>(this ICollectionObservable<T> source, Func<T, IValueObservable<U>> orderBy)
|
|
204
|
+
=> new ListOperator<T>(source.context, operand => new OrderByObservable<T, U>(source, orderBy, true, operand));
|
|
205
|
+
|
|
206
|
+
public static IValueObservable<int> ObservableCount<T>(this ICollectionObservable<T> source)
|
|
207
|
+
=> new ValueOperator<int>(source.context, operand => new CountObservable<T>(source, operand));
|
|
208
|
+
|
|
209
|
+
public static IValueObservable<bool> ObservableContains<T>(this ICollectionObservable<T> source, T contains)
|
|
210
|
+
=> source.ObservableContains(new ObservableValue<T>(source.context, contains));
|
|
211
|
+
|
|
212
|
+
public static IValueObservable<bool> ObservableContains<T>(this ICollectionObservable<T> source, IValueObservable<T> contains)
|
|
213
|
+
=> new ValueOperator<bool>(source.context, operand => new ContainsObservable<T>(source, contains, operand));
|
|
214
|
+
|
|
215
|
+
public static IValueObservable<T> ObservableFirstOrDefault<T>(this ICollectionObservable<T> source, Func<T, bool> validate)
|
|
216
|
+
=> source.ObservableFirstOrDefault(x => new ObservableValue<bool>(source.context, validate(x)));
|
|
217
|
+
|
|
218
|
+
public static IValueObservable<T> ObservableFirstOrDefault<T>(this ICollectionObservable<T> source, Func<T, IValueObservable<bool>> validate)
|
|
219
|
+
=> source.ObservableFirst(validate).ObservableSelect(x => x.found ? x.value : default);
|
|
220
|
+
|
|
221
|
+
public static IValueObservable<(bool found, T value)> ObservableFirst<T>(this ICollectionObservable<T> source, Func<T, bool> validate)
|
|
222
|
+
=> source.ObservableFirst(x => new ObservableValue<bool>(source.context, validate(x)));
|
|
223
|
+
|
|
224
|
+
public static IValueObservable<(bool found, T value)> ObservableFirst<T>(this ICollectionObservable<T> source, Func<T, IValueObservable<bool>> validate)
|
|
225
|
+
=> new ValueOperator<(bool found, T value)>(source.context, operand => new FirstObservable<T>(source, validate, operand));
|
|
226
|
+
|
|
227
|
+
public static IValueObservable<(bool keyPresent, TValue value)> ObservableTrack<TKey, TValue>(this IDictionaryObservable<TKey, TValue> source, TKey key)
|
|
228
|
+
=> source.ObservableTrack(new ObservableValue<TKey>(source.context, key));
|
|
229
|
+
|
|
230
|
+
public static IValueObservable<(bool keyPresent, TValue value)> ObservableTrack<TKey, TValue>(this IDictionaryObservable<TKey, TValue> source, IValueObservable<TKey> key)
|
|
231
|
+
=> new ValueOperator<(bool keyPresent, TValue value)>(source.context, operand => new TrackObservable<TKey, TValue>(source, key, operand));
|
|
232
|
+
|
|
233
|
+
public static ICollectionObservable<TValue> ObservableTrack<TKey, TValue>(this IDictionaryObservable<TKey, TValue> source, ICollectionObservable<TKey> keys)
|
|
234
|
+
=> keys.ObservableSelect(x => source.ObservableTrack(x)).ObservableWhere(x => x.keyPresent).ObservableSelect(((bool keyPresent, TValue value) x) => x.value);
|
|
235
|
+
|
|
236
|
+
public static IListObservable<T> ObservableUnwrap<T>(this IListObservable<IValueObservable<T>> source)
|
|
237
|
+
=> new ListOperator<T>(source.context, operand => new UnwrapListObservable<T>(source, operand));
|
|
238
|
+
|
|
239
|
+
public static IListObservable<U> ObservableSelect<T, U>(this IListObservable<T> source, Func<T, U> select)
|
|
240
|
+
=> new ListOperator<U>(source.context, operand => new SelectListObservable<T, U>(source, select, operand));
|
|
241
|
+
|
|
242
|
+
public static IListObservable<U> ObservableSelect<T, U>(this IListObservable<T> source, Func<T, IValueObservable<U>> select)
|
|
243
|
+
=> source.ObservableSelect<T, IValueObservable<U>>(select).ObservableUnwrap();
|
|
244
|
+
|
|
245
|
+
public static IValueObservable<(bool found, int index)> ObservableIndexOf<T>(this IListObservable<T> source, T value)
|
|
246
|
+
=> source.ObservableIndexOf(new ObservableValue<T>(source.context, value));
|
|
247
|
+
|
|
248
|
+
public static IValueObservable<(bool found, int index)> ObservableIndexOf<T>(this IListObservable<T> source, IValueObservable<T> value)
|
|
249
|
+
=> new ValueOperator<(bool found, int index)>(source.context, operand => new IndexOfObservable<T>(source, value, operand));
|
|
250
|
+
|
|
251
|
+
public static IDictionaryObservable<TKey, TValue> ObservableToDictionary<T, TKey, TValue>(this ICollectionObservable<T> source, Func<T, IValueObservable<TKey>> selectKey, Func<T, IValueObservable<TValue>> selectValue)
|
|
252
|
+
=> new DictionaryOperator<TKey, TValue>(source.context, operand => new ToDictionaryObservable<T, TKey, TValue>(source, selectKey, selectValue, operand));
|
|
253
|
+
|
|
254
|
+
public static IDictionaryObservable<TKey, TValue> ObservableToDictionary<T, TKey, TValue>(this ICollectionObservable<T> source, Func<T, TKey> selectKey, Func<T, IValueObservable<TValue>> selectValue)
|
|
255
|
+
=> new DictionaryOperator<TKey, TValue>(source.context, operand => new ToDictionaryObservable<T, TKey, TValue>(source, x => new ObservableValue<TKey>(source.context, selectKey(x)), selectValue, operand));
|
|
256
|
+
|
|
257
|
+
public static IDictionaryObservable<TKey, TValue> ObservableToDictionary<T, TKey, TValue>(this ICollectionObservable<T> source, Func<T, IValueObservable<TKey>> selectKey, Func<T, TValue> selectValue)
|
|
258
|
+
=> new DictionaryOperator<TKey, TValue>(source.context, operand => new ToDictionaryObservable<T, TKey, TValue>(source, selectKey, x => new ObservableValue<TValue>(source.context, selectValue(x)), operand));
|
|
259
|
+
|
|
260
|
+
public static IDictionaryObservable<TKey, TValue> ObservableToDictionary<T, TKey, TValue>(this ICollectionObservable<T> source, Func<T, TKey> selectKey, Func<T, TValue> selectValue)
|
|
261
|
+
=> new DictionaryOperator<TKey, TValue>(source.context, operand => new ToDictionaryObservable<T, TKey, TValue>(source, x => new ObservableValue<TKey>(source.context, selectKey(x)), x => new ObservableValue<TValue>(source.context, selectValue(x)), operand));
|
|
262
|
+
|
|
263
|
+
public static IValueObservable<T> AsObservable<T>(this IValueObservable<T> observable)
|
|
264
|
+
=> observable;
|
|
265
|
+
|
|
266
|
+
public static ICollectionObservable<T> AsObservable<T>(this ICollectionObservable<T> observable)
|
|
267
|
+
=> observable;
|
|
268
|
+
|
|
269
|
+
public static IListObservable<T> AsObservable<T>(this IListObservable<T> observable)
|
|
270
|
+
=> observable;
|
|
271
|
+
|
|
272
|
+
public static IDictionaryObservable<TKey, TValue> AsObservable<TKey, TValue>(this IDictionaryObservable<TKey, TValue> observable)
|
|
273
|
+
=> observable;
|
|
274
|
+
|
|
275
|
+
public static ISetObservable<T> AsObservable<T>(this ISetObservable<T> observable)
|
|
276
|
+
=> observable;
|
|
277
|
+
|
|
278
|
+
public static T Peek<T>(this IValueObservable<T> source)
|
|
279
|
+
{
|
|
280
|
+
T result = default;
|
|
281
|
+
source.Subscribe(x => result = x).Dispose();
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default) where T : IOperation
|
|
286
|
+
=> source.Subscribe(new Observer<T>(onNext, onDispose, onError), immediate, priority);
|
|
287
|
+
|
|
288
|
+
public static IDisposable Subscribe(this IValueObservable source, Action<object> onNext = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
289
|
+
=> source.Subscribe(new ValueObserver(onNext, onDispose, onError), immediate, priority);
|
|
290
|
+
|
|
291
|
+
public static IDisposable Subscribe<T>(this IValueObservable<T> source, Action<T> onNext = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
292
|
+
=> source.Subscribe(new ValueObserver<T>(onNext, onDispose, onError), immediate, priority);
|
|
293
|
+
|
|
294
|
+
public static IDisposable Subscribe<T>(this IObservable<BatchOp<T>> source, Action<IReadOnlyList<T>> onNext = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default) where T : IOperation
|
|
295
|
+
=> source.Subscribe(new Observer<BatchOp<T>>(onNext: x => onNext?.Invoke(x.operations), onDispose, onError), immediate, priority);
|
|
296
|
+
|
|
297
|
+
public static IDisposable Subscribe(this IDictionaryObservable source, Action<KeyValuePair<object, object>> onAdd = default, Action<KeyValuePair<object, object>> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
298
|
+
=> source.Subscribe(new DictionaryObserver(
|
|
299
|
+
onAdd: onAdd == null ? null : (_, kvp) => onAdd?.Invoke(kvp),
|
|
300
|
+
onRemove: onRemove == null ? null : (_, kvp) => onRemove?.Invoke(kvp),
|
|
301
|
+
onError: onError,
|
|
302
|
+
onDispose: onDispose
|
|
303
|
+
), immediate, priority);
|
|
304
|
+
|
|
305
|
+
public static IDisposable SubscribeWithId(this IDictionaryObservable source, Action<uint, KeyValuePair<object, object>> onAdd = default, Action<uint, KeyValuePair<object, object>> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
306
|
+
=> source.Subscribe(new DictionaryObserver(
|
|
307
|
+
onAdd: onAdd,
|
|
308
|
+
onRemove: onRemove,
|
|
309
|
+
onError: onError,
|
|
310
|
+
onDispose: onDispose
|
|
311
|
+
), immediate, priority);
|
|
312
|
+
|
|
313
|
+
public static IDisposable Subscribe<TKey, TValue>(this IDictionaryObservable<TKey, TValue> source, Action<KeyValuePair<TKey, TValue>> onAdd = default, Action<KeyValuePair<TKey, TValue>> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
314
|
+
=> source.Subscribe(new DictionaryObserver<TKey, TValue>(
|
|
315
|
+
onAdd: onAdd == null ? null : (_, kvp) => onAdd?.Invoke(kvp),
|
|
316
|
+
onRemove: onRemove == null ? null : (_, kvp) => onRemove?.Invoke(kvp),
|
|
317
|
+
onError: onError,
|
|
318
|
+
onDispose: onDispose
|
|
319
|
+
), immediate, priority);
|
|
320
|
+
|
|
321
|
+
public static IDisposable SubscribeWithId<TKey, TValue>(this IDictionaryObservable<TKey, TValue> source, Action<uint, KeyValuePair<TKey, TValue>> onAdd = default, Action<uint, KeyValuePair<TKey, TValue>> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
322
|
+
=> source.Subscribe(new DictionaryObserver<TKey, TValue>(
|
|
323
|
+
onAdd: onAdd,
|
|
324
|
+
onRemove: onRemove,
|
|
325
|
+
onError: onError,
|
|
326
|
+
onDispose: onDispose
|
|
327
|
+
), immediate, priority);
|
|
328
|
+
|
|
329
|
+
public static IDisposable Subscribe(this IListObservable source, Action<int, object> onAdd = default, Action<int, object> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
330
|
+
=> source.Subscribe(new ListObserver(
|
|
331
|
+
onAdd: onAdd == null ? null : (_, index, element) => onAdd?.Invoke(index, element),
|
|
332
|
+
onRemove: onRemove == null ? null : (_, index, element) => onRemove?.Invoke(index, element),
|
|
333
|
+
onError: onError,
|
|
334
|
+
onDispose: onDispose
|
|
335
|
+
), immediate, priority);
|
|
336
|
+
|
|
337
|
+
public static IDisposable SubscribeWithId(this IListObservable source, Action<uint, int, object> onAdd = default, Action<uint, int, object> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
338
|
+
=> source.Subscribe(new ListObserver(
|
|
339
|
+
onAdd: onAdd,
|
|
340
|
+
onRemove: onRemove,
|
|
341
|
+
onError: onError,
|
|
342
|
+
onDispose: onDispose
|
|
343
|
+
), immediate, priority);
|
|
344
|
+
|
|
345
|
+
public static IDisposable Subscribe<T>(this IListObservable<T> source, Action<int, T> onAdd = default, Action<int, T> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
346
|
+
=> source.Subscribe(new ListObserver<T>(
|
|
347
|
+
onAdd: onAdd == null ? null : (_, index, element) => onAdd?.Invoke(index, element),
|
|
348
|
+
onRemove: onRemove == null ? null : (_, index, element) => onRemove?.Invoke(index, element),
|
|
349
|
+
onError: onError,
|
|
350
|
+
onDispose: onDispose
|
|
351
|
+
), immediate, priority);
|
|
352
|
+
|
|
353
|
+
public static IDisposable SubscribeWithId<T>(this IListObservable<T> source, Action<uint, int, T> onAdd = default, Action<uint, int, T> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
354
|
+
=> source.Subscribe(new ListObserver<T>(
|
|
355
|
+
onAdd: onAdd,
|
|
356
|
+
onRemove: onRemove,
|
|
357
|
+
onError: onError,
|
|
358
|
+
onDispose: onDispose
|
|
359
|
+
), immediate, priority);
|
|
360
|
+
|
|
361
|
+
public static IDisposable Subscribe(this ICollectionObservable source, Action<object> onAdd = default, Action<object> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
362
|
+
=> source.Subscribe(new CollectionObserver(
|
|
363
|
+
onAdd: onAdd == null ? null : (_, element) => onAdd?.Invoke(element),
|
|
364
|
+
onRemove: onRemove == null ? null : (_, element) => onRemove?.Invoke(element),
|
|
365
|
+
onError: onError,
|
|
366
|
+
onDispose: onDispose
|
|
367
|
+
), immediate, priority);
|
|
368
|
+
|
|
369
|
+
public static IDisposable SubscribeWithId(this ICollectionObservable source, Action<uint, object> onAdd = default, Action<uint, object> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
370
|
+
=> source.Subscribe(new CollectionObserver(
|
|
371
|
+
onAdd: onAdd,
|
|
372
|
+
onRemove: onRemove,
|
|
373
|
+
onError: onError,
|
|
374
|
+
onDispose: onDispose
|
|
375
|
+
), immediate, priority);
|
|
376
|
+
|
|
377
|
+
public static IDisposable Subscribe<T>(this ICollectionObservable<T> source, Action<T> onAdd = default, Action<T> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
378
|
+
=> source.Subscribe(new CollectionObserver<T>(
|
|
379
|
+
onAdd: onAdd == null ? null : (_, element) => onAdd?.Invoke(element),
|
|
380
|
+
onRemove: onRemove == null ? null : (_, element) => onRemove?.Invoke(element),
|
|
381
|
+
onError: onError,
|
|
382
|
+
onDispose: onDispose
|
|
383
|
+
), immediate, priority);
|
|
384
|
+
|
|
385
|
+
public static IDisposable SubscribeWithId<T>(this ICollectionObservable<T> source, Action<uint, T> onAdd = default, Action<uint, T> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
386
|
+
=> source.Subscribe(new CollectionObserver<T>(
|
|
387
|
+
onAdd: onAdd,
|
|
388
|
+
onRemove: onRemove,
|
|
389
|
+
onError: onError,
|
|
390
|
+
onDispose: onDispose
|
|
391
|
+
), immediate, priority);
|
|
392
|
+
|
|
393
|
+
public static IDisposable Subscribe(this ISetObservable source, Action<object> onAdd = default, Action<object> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
394
|
+
=> source.Subscribe(new SetObserver(
|
|
395
|
+
onAdd: onAdd == null ? null : (_, element) => onAdd?.Invoke(element),
|
|
396
|
+
onRemove: onRemove == null ? null : (_, element) => onRemove?.Invoke(element),
|
|
397
|
+
onError: onError,
|
|
398
|
+
onDispose: onDispose
|
|
399
|
+
), immediate, priority);
|
|
400
|
+
|
|
401
|
+
public static IDisposable SubscribeWithId(this ISetObservable source, Action<uint, object> onAdd = default, Action<uint, object> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
402
|
+
=> source.Subscribe(new SetObserver(
|
|
403
|
+
onAdd: onAdd,
|
|
404
|
+
onRemove: onRemove,
|
|
405
|
+
onError: onError,
|
|
406
|
+
onDispose: onDispose
|
|
407
|
+
), immediate, priority);
|
|
408
|
+
|
|
409
|
+
public static IDisposable Subscribe<T>(this ISetObservable<T> source, Action<T> onAdd = default, Action<T> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
410
|
+
=> source.Subscribe(new SetObserver<T>(
|
|
411
|
+
onAdd: onAdd == null ? null : (_, element) => onAdd?.Invoke(element),
|
|
412
|
+
onRemove: onRemove == null ? null : (_, element) => onRemove?.Invoke(element),
|
|
413
|
+
onError: onError,
|
|
414
|
+
onDispose: onDispose
|
|
415
|
+
), immediate, priority);
|
|
416
|
+
|
|
417
|
+
public static IDisposable SubscribeWithId<T>(this ISetObservable<T> source, Action<uint, T> onAdd = default, Action<uint, T> onRemove = default, Action<Exception> onError = default, Action onDispose = default, bool immediate = default, uint? priority = default)
|
|
418
|
+
=> source.Subscribe(new SetObserver<T>(
|
|
419
|
+
onAdd: onAdd,
|
|
420
|
+
onRemove: onRemove,
|
|
421
|
+
onError: onError,
|
|
422
|
+
onDispose: onDispose
|
|
423
|
+
), immediate, priority);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
public class Disposable : IDisposable
|
|
427
|
+
{
|
|
428
|
+
private bool _disposed;
|
|
429
|
+
private Action _onDispose;
|
|
430
|
+
|
|
431
|
+
public Disposable(Action onDispose)
|
|
432
|
+
{
|
|
433
|
+
_onDispose = onDispose;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
public void Dispose()
|
|
437
|
+
{
|
|
438
|
+
if (_disposed)
|
|
439
|
+
return;
|
|
440
|
+
|
|
441
|
+
_disposed = true;
|
|
442
|
+
_onDispose?.Invoke();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
public class ComposedDisposable : IDisposable
|
|
447
|
+
{
|
|
448
|
+
private bool _disposed;
|
|
449
|
+
private IDisposable[] _disposables;
|
|
450
|
+
|
|
451
|
+
public ComposedDisposable(params IDisposable[] disposables)
|
|
452
|
+
{
|
|
453
|
+
_disposables = disposables;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
public void Dispose()
|
|
457
|
+
{
|
|
458
|
+
if (_disposed)
|
|
459
|
+
return;
|
|
460
|
+
|
|
461
|
+
_disposed = true;
|
|
462
|
+
|
|
463
|
+
foreach (var disposable in _disposables)
|
|
464
|
+
disposable?.Dispose();
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
|
|
4
|
+
namespace ObserveThing
|
|
5
|
+
{
|
|
6
|
+
public interface IPendingObserver
|
|
7
|
+
{
|
|
8
|
+
uint priority { get; }
|
|
9
|
+
bool immediate { get; }
|
|
10
|
+
bool disposed { get; }
|
|
11
|
+
void SendNext();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public class ObservationContext
|
|
15
|
+
{
|
|
16
|
+
private PriorityQueue<IPendingObserver, ObserverOrder> _pendingImmediateObservers = new PriorityQueue<IPendingObserver, ObserverOrder>(new ObserverOrderComparer());
|
|
17
|
+
private PriorityQueue<IPendingObserver, ObserverOrder> _pendingObservers = new PriorityQueue<IPendingObserver, ObserverOrder>(new ObserverOrderComparer());
|
|
18
|
+
|
|
19
|
+
private HashSet<uint> _allocatedPriorties = new HashSet<uint>();
|
|
20
|
+
private CollectionIdProvider _idProvider;
|
|
21
|
+
|
|
22
|
+
private bool _notifyingImmediateObservers = false;
|
|
23
|
+
private bool _notifyingObservers = false;
|
|
24
|
+
private bool _executingBatch = false;
|
|
25
|
+
private int _registrationOrder = 0;
|
|
26
|
+
|
|
27
|
+
private struct ObserverOrder
|
|
28
|
+
{
|
|
29
|
+
public uint priority;
|
|
30
|
+
public int registrationOrder;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private class ObserverOrderComparer : IComparer<ObserverOrder>
|
|
34
|
+
{
|
|
35
|
+
public int Compare(ObserverOrder x, ObserverOrder y)
|
|
36
|
+
{
|
|
37
|
+
if (x.priority != y.priority)
|
|
38
|
+
return x.priority.CompareTo(y.priority);
|
|
39
|
+
|
|
40
|
+
return x.registrationOrder.CompareTo(y.registrationOrder);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public ObservationContext()
|
|
45
|
+
{
|
|
46
|
+
_idProvider = new CollectionIdProvider(x => _allocatedPriorties.Contains(x));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public void ExecuteBatchOperation(Action batchOperation)
|
|
50
|
+
{
|
|
51
|
+
bool wasExecutingBatch = _executingBatch;
|
|
52
|
+
_executingBatch = true;
|
|
53
|
+
batchOperation.Invoke();
|
|
54
|
+
_executingBatch = wasExecutingBatch;
|
|
55
|
+
|
|
56
|
+
NotifyPendingObserversIfNecessary();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private void DrainPendingObserverQueue()
|
|
60
|
+
{
|
|
61
|
+
while (_pendingObservers.TryDequeue(out var observer, out var _))
|
|
62
|
+
{
|
|
63
|
+
if (observer.disposed)
|
|
64
|
+
continue;
|
|
65
|
+
|
|
66
|
+
observer.SendNext();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private void DrainPendingImmediateObserverQueue()
|
|
71
|
+
{
|
|
72
|
+
while (_pendingImmediateObservers.TryDequeue(out var observer, out var _))
|
|
73
|
+
{
|
|
74
|
+
if (observer.disposed)
|
|
75
|
+
continue;
|
|
76
|
+
|
|
77
|
+
observer.SendNext();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public uint AllocateObserverPriority()
|
|
82
|
+
{
|
|
83
|
+
var priority = _idProvider.GetUnusedId();
|
|
84
|
+
_allocatedPriorties.Add(priority);
|
|
85
|
+
return priority;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public void DeallocateObserverPriority(uint priority)
|
|
89
|
+
{
|
|
90
|
+
_allocatedPriorties.Remove(priority);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public void RegisterPendingObserver(IPendingObserver observer)
|
|
94
|
+
{
|
|
95
|
+
if (observer.immediate)
|
|
96
|
+
{
|
|
97
|
+
_pendingImmediateObservers.Enqueue(observer, new() { priority = observer.priority, registrationOrder = _registrationOrder });
|
|
98
|
+
}
|
|
99
|
+
else
|
|
100
|
+
{
|
|
101
|
+
_pendingObservers.Enqueue(observer, new() { priority = observer.priority, registrationOrder = _registrationOrder });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_registrationOrder++;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public void NotifyPendingObserversIfNecessary()
|
|
108
|
+
{
|
|
109
|
+
if (_notifyingImmediateObservers)
|
|
110
|
+
return;
|
|
111
|
+
|
|
112
|
+
_notifyingImmediateObservers = true;
|
|
113
|
+
DrainPendingImmediateObserverQueue(); // immediate notifications should get sent even if we're in a batch
|
|
114
|
+
_notifyingImmediateObservers = false;
|
|
115
|
+
|
|
116
|
+
if (_notifyingObservers || _executingBatch)
|
|
117
|
+
return;
|
|
118
|
+
|
|
119
|
+
_notifyingObservers = true;
|
|
120
|
+
DrainPendingObserverQueue();
|
|
121
|
+
_notifyingObservers = false;
|
|
122
|
+
|
|
123
|
+
_registrationOrder = 0;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|