com.fofx.observething 1.1.0-dev.36048653905 → 1.1.1-dev.161

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/Runtime/{Operators/IInitializationOperationsProvider.cs → IInitializationOperationsProvider.cs} +1 -1
  2. package/Runtime/{IObservable.cs → Observables/IObservable.cs} +13 -9
  3. package/Runtime/{Implementations/ObservableBase.cs → Observables/Observable.cs} +6 -19
  4. package/Runtime/{Implementations → Observables}/ObservableCollection.cs +6 -15
  5. package/Runtime/{Implementations → Observables}/ObservableDictionary.cs +7 -18
  6. package/Runtime/{Implementations/Observable.cs → Observables/ObservableEventStream.cs} +11 -3
  7. package/Runtime/{Implementations → Observables}/ObservableList.cs +3 -13
  8. package/Runtime/{Implementations → Observables}/ObservableSet.cs +6 -15
  9. package/Runtime/{Implementations → Observables}/ObservableValue.cs +4 -11
  10. package/Runtime/Observables.meta +1 -1
  11. package/Runtime/ObservationDefaults.cs +10 -0
  12. package/Runtime/ObservationDefaults.cs.meta +2 -0
  13. package/Runtime/Observers.cs +51 -64
  14. package/Runtime/Operators/BatchOperator.cs +52 -51
  15. package/Runtime/Operators/BatchOperator.cs.meta +1 -1
  16. package/Runtime/{Observables/CastObservable.cs → Operators/CastOperator.cs} +10 -10
  17. package/Runtime/{Observables/CombineObservable.cs → Operators/CombineOperator.cs} +10 -10
  18. package/Runtime/{Observables/CombineValueObservable.cs → Operators/CombineValueOperator.cs} +12 -12
  19. package/Runtime/{Observables/ConcatObservable.cs → Operators/ConcatOperator.cs} +2 -2
  20. package/Runtime/{Observables/ContainsObservable.cs → Operators/ContainsOperator.cs} +2 -2
  21. package/Runtime/Operators/ContainsOperator.cs.meta +2 -0
  22. package/Runtime/{Observables/CountObservable.cs → Operators/CountOperator.cs} +2 -2
  23. package/Runtime/{Observables/DistinctObservable.cs → Operators/DistinctOperator.cs} +2 -2
  24. package/Runtime/Operators/{CollectionOperator.cs → Factories/CollectionOperatorFactory.cs} +2 -9
  25. package/Runtime/Operators/{DictionaryOperator.cs → Factories/DictionaryOperatorFactory.cs} +2 -9
  26. package/Runtime/Operators/{ObservableOperator.cs → Factories/EventStreamOperatorFactory.cs} +17 -10
  27. package/Runtime/Operators/{ListOperator.cs → Factories/ListOperatorFactory.cs} +2 -9
  28. package/Runtime/Operators/{Operator.cs → Factories/OperatorFactory.cs} +8 -8
  29. package/Runtime/Operators/{SetOperator.cs → Factories/SetOperatorFactory.cs} +2 -9
  30. package/Runtime/Operators/{ValueOperator.cs → Factories/ValueOperator.cs} +2 -9
  31. package/Runtime/{Implementations.meta → Operators/Factories.meta} +1 -1
  32. package/Runtime/{Observables/FirstObservable.cs → Operators/FirstOperator.cs} +2 -2
  33. package/Runtime/{Observables/IndexOfObservable.cs → Operators/IndexOfOperator.cs} +2 -2
  34. package/Runtime/Operators/OperationStreamOperator.cs +212 -0
  35. package/Runtime/{Observables.cs → Operators/Operators.cs} +105 -73
  36. package/Runtime/{Observables/OrderByObservable.cs → Operators/OrderByOperator.cs} +2 -2
  37. package/Runtime/{Observables/SelectCollectionObservable.cs → Operators/SelectCollectionOperator.cs} +2 -2
  38. package/Runtime/{Observables/SelectListObservable.cs → Operators/SelectListOperator.cs} +2 -2
  39. package/Runtime/{Observables/SelectManyObservable.cs → Operators/SelectManyOperator.cs} +2 -2
  40. package/Runtime/{Observables/SkipWhileObservable.cs → Operators/SkipWhileOperator.cs} +2 -2
  41. package/Runtime/{Observables/ThenObservable.cs → Operators/ThenOperator.cs} +2 -2
  42. package/Runtime/{Observables/ToDictionaryObservable.cs → Operators/ToDictionaryOperator.cs} +3 -3
  43. package/Runtime/{Observables/TrackObservable.cs → Operators/TrackOperator.cs} +2 -2
  44. package/Runtime/{Observables/UnwrapCollectionObservable.cs → Operators/UnwrapCollectionOperator.cs} +2 -2
  45. package/Runtime/{Observables/UnwrapListObservable.cs → Operators/UnwrapListOperator.cs} +2 -2
  46. package/Runtime/{Observables/UnwrapValueObservable.cs → Operators/UnwrapValueOperator.cs} +2 -2
  47. package/Runtime/{Observables/WhereObservable.cs → Operators/WhereOperator.cs} +2 -2
  48. package/Runtime/{Observables/WithPreviousObservable.cs → Operators/WithPreviousOperator.cs} +2 -2
  49. package/Tests/CollectionObservableTests.cs +1 -1
  50. package/Tests/DictionaryObservableTests.cs +1 -1
  51. package/Tests/ListObservableTests.cs +1 -1
  52. package/Tests/ObservationContextTests.cs +109 -83
  53. package/Tests/ValueObservableTests.cs +1 -1
  54. package/package.json +5 -4
  55. package/Runtime/Observables/BatchObservable.cs +0 -72
  56. package/Runtime/Observables/BatchObservable.cs.meta +0 -2
  57. package/Runtime/Observables/ContainsObservable.cs.meta +0 -2
  58. package/Runtime/Observables/OperationStreamObservable.cs +0 -194
  59. /package/Runtime/{Operators/IInitializationOperationsProvider.cs.meta → IInitializationOperationsProvider.cs.meta} +0 -0
  60. /package/Runtime/{IObservable.cs.meta → Observables/IObservable.cs.meta} +0 -0
  61. /package/Runtime/{Implementations/ObservableBase.cs.meta → Observables/Observable.cs.meta} +0 -0
  62. /package/Runtime/{Implementations → Observables}/ObservableCollection.cs.meta +0 -0
  63. /package/Runtime/{Implementations → Observables}/ObservableDictionary.cs.meta +0 -0
  64. /package/Runtime/{Implementations/Observable.cs.meta → Observables/ObservableEventStream.cs.meta} +0 -0
  65. /package/Runtime/{Implementations → Observables}/ObservableList.cs.meta +0 -0
  66. /package/Runtime/{Implementations → Observables}/ObservableSet.cs.meta +0 -0
  67. /package/Runtime/{Implementations → Observables}/ObservableValue.cs.meta +0 -0
  68. /package/Runtime/{Observables/CastObservable.cs.meta → Operators/CastOperator.cs.meta} +0 -0
  69. /package/Runtime/{Observables/CombineObservable.cs.meta → Operators/CombineOperator.cs.meta} +0 -0
  70. /package/Runtime/{Observables/CombineValueObservable.cs.meta → Operators/CombineValueOperator.cs.meta} +0 -0
  71. /package/Runtime/{Observables/ConcatObservable.cs.meta → Operators/ConcatOperator.cs.meta} +0 -0
  72. /package/Runtime/{Observables/CountObservable.cs.meta → Operators/CountOperator.cs.meta} +0 -0
  73. /package/Runtime/{Observables/DistinctObservable.cs.meta → Operators/DistinctOperator.cs.meta} +0 -0
  74. /package/Runtime/Operators/{CollectionOperator.cs.meta → Factories/CollectionOperatorFactory.cs.meta} +0 -0
  75. /package/Runtime/Operators/{DictionaryOperator.cs.meta → Factories/DictionaryOperatorFactory.cs.meta} +0 -0
  76. /package/Runtime/Operators/{ObservableOperator.cs.meta → Factories/EventStreamOperatorFactory.cs.meta} +0 -0
  77. /package/Runtime/Operators/{ListOperator.cs.meta → Factories/ListOperatorFactory.cs.meta} +0 -0
  78. /package/Runtime/Operators/{Operator.cs.meta → Factories/OperatorFactory.cs.meta} +0 -0
  79. /package/Runtime/Operators/{SetOperator.cs.meta → Factories/SetOperatorFactory.cs.meta} +0 -0
  80. /package/Runtime/Operators/{ValueOperator.cs.meta → Factories/ValueOperator.cs.meta} +0 -0
  81. /package/Runtime/{Observables/FirstObservable.cs.meta → Operators/FirstOperator.cs.meta} +0 -0
  82. /package/Runtime/{Observables/IndexOfObservable.cs.meta → Operators/IndexOfOperator.cs.meta} +0 -0
  83. /package/Runtime/{Observables/OperationStreamObservable.cs.meta → Operators/OperationStreamOperator.cs.meta} +0 -0
  84. /package/Runtime/{Observables.cs.meta → Operators/Operators.cs.meta} +0 -0
  85. /package/Runtime/{Observables/OrderByObservable.cs.meta → Operators/OrderByOperator.cs.meta} +0 -0
  86. /package/Runtime/{Observables/SelectCollectionObservable.cs.meta → Operators/SelectCollectionOperator.cs.meta} +0 -0
  87. /package/Runtime/{Observables/SelectListObservable.cs.meta → Operators/SelectListOperator.cs.meta} +0 -0
  88. /package/Runtime/{Observables/SelectManyObservable.cs.meta → Operators/SelectManyOperator.cs.meta} +0 -0
  89. /package/Runtime/{Observables/SelectValueObservable.cs → Operators/SelectValueOperator.cs} +0 -0
  90. /package/Runtime/{Observables/SelectValueObservable.cs.meta → Operators/SelectValueOperator.cs.meta} +0 -0
  91. /package/Runtime/{Observables/SkipWhileObservable.cs.meta → Operators/SkipWhileOperator.cs.meta} +0 -0
  92. /package/Runtime/{Observables/ThenObservable.cs.meta → Operators/ThenOperator.cs.meta} +0 -0
  93. /package/Runtime/{Observables/ToDictionaryObservable.cs.meta → Operators/ToDictionaryOperator.cs.meta} +0 -0
  94. /package/Runtime/{Observables/TrackObservable.cs.meta → Operators/TrackOperator.cs.meta} +0 -0
  95. /package/Runtime/{Observables/UnwrapCollectionObservable.cs.meta → Operators/UnwrapCollectionOperator.cs.meta} +0 -0
  96. /package/Runtime/{Observables/UnwrapListObservable.cs.meta → Operators/UnwrapListOperator.cs.meta} +0 -0
  97. /package/Runtime/{Observables/UnwrapValueObservable.cs.meta → Operators/UnwrapValueOperator.cs.meta} +0 -0
  98. /package/Runtime/{Observables/WhereObservable.cs.meta → Operators/WhereOperator.cs.meta} +0 -0
  99. /package/Runtime/{Observables/WithPreviousObservable.cs.meta → Operators/WithPreviousOperator.cs.meta} +0 -0
@@ -3,7 +3,7 @@ using System.Collections.Generic;
3
3
 
4
4
  namespace ObserveThing
5
5
  {
6
- public interface IInitializationOperationsProvider<T> : IDisposable where T : IOperation
6
+ public interface IInitializationOperationsProvider<T> : IDisposable
7
7
  {
8
8
  IEnumerable<T> GetInitializationOperations();
9
9
  }
@@ -3,13 +3,22 @@ using System.Collections.Generic;
3
3
 
4
4
  namespace ObserveThing
5
5
  {
6
- public interface IObservable<out T> where T : IOperation
6
+ public interface IObservable
7
7
  {
8
8
  ObservationContext context { get; }
9
- IDisposable Subscribe(IObserver<T> observer, bool immediate = default, uint? priority = default);
10
9
  }
11
10
 
12
- public interface IValueObservable : IObservable<IOperation>
11
+ public interface IEventStreamObservable : IObservable
12
+ {
13
+ IDisposable Subscribe(IEventStreamObserver observer, bool immediate = default, uint? priority = default);
14
+ }
15
+
16
+ public interface IEventStreamObservable<out T> : IEventStreamObservable
17
+ {
18
+ IDisposable Subscribe(IEventStreamObserver<T> observer, bool immediate = default, uint? priority = default);
19
+ }
20
+
21
+ public interface IValueObservable : IObservable
13
22
  {
14
23
  IDisposable Subscribe(IValueObserver observer, bool immediate = default, uint? priority = default);
15
24
  }
@@ -19,7 +28,7 @@ namespace ObserveThing
19
28
  IDisposable Subscribe(IValueObserver<T> observer, bool immediate = default, uint? priority = default);
20
29
  }
21
30
 
22
- public interface ICollectionObservable : IObservable<IOperation>
31
+ public interface ICollectionObservable : IObservable
23
32
  {
24
33
  IDisposable Subscribe(ICollectionObserver observer, bool immediate = default, uint? priority = default);
25
34
  }
@@ -58,9 +67,4 @@ namespace ObserveThing
58
67
  {
59
68
  IDisposable Subscribe(IDictionaryObserver<TKey, TValue> observer, bool immediate = default, uint? priority = default);
60
69
  }
61
-
62
- // public interface IBatchObservable<out T> : IObservable<IOperation> where T : IOperation
63
- // {
64
- // public IDisposable Subscribe(IBatchObserver<T> observer, bool immediate = false, uint? priority = default);
65
- // }
66
70
  }
@@ -4,18 +4,11 @@ using System.Linq;
4
4
 
5
5
  namespace ObserveThing
6
6
  {
7
- public interface IOperation
8
- {
9
- IObservable<IOperation> source { get; }
10
- }
11
-
12
- public abstract class ObservableBase<TObserver, TOperation> : IObservable<IOperation>, IDisposable
13
- where TObserver : IObserverBase
14
- where TOperation : IOperation
7
+ public abstract class Observable<TObserver, TOperation> : IObservable, IDisposable where TObserver : IObserver
15
8
  {
16
9
  private class ObserverData : IPendingObserver, IDisposable
17
10
  {
18
- public IObserverBase observer { get; }
11
+ public IObserver observer { get; }
19
12
  public bool immediate { get; }
20
13
  public uint priority { get; }
21
14
  public bool priorityAllocated { get; }
@@ -25,7 +18,7 @@ namespace ObserveThing
25
18
  private Action<TOperation> _sendOperation;
26
19
  private Action<ObserverData> _onDispose;
27
20
 
28
- public ObserverData(IObserverBase observer, bool immediate, uint priority, bool priorityAllocated, Action<TOperation> sendOperation, Action<ObserverData> onDispose)
21
+ public ObserverData(IObserver observer, bool immediate, uint priority, bool priorityAllocated, Action<TOperation> sendOperation, Action<ObserverData> onDispose)
29
22
  {
30
23
  this.observer = observer;
31
24
  this.immediate = immediate;
@@ -74,9 +67,9 @@ namespace ObserveThing
74
67
 
75
68
  private List<ObserverData> _observers = new List<ObserverData>();
76
69
 
77
- public ObservableBase(ObservationContext context)
70
+ public Observable(ObservationContext context)
78
71
  {
79
- this.context = context ?? Settings.DefaultObservationContext;
72
+ this.context = context ?? ObservationDefaults.DefaultObservationContext;
80
73
  }
81
74
 
82
75
  private void HandleObserverDisposed(ObserverData data)
@@ -118,10 +111,7 @@ namespace ObserveThing
118
111
 
119
112
  protected abstract IEnumerable<TOperation> GetInitializationOperations();
120
113
 
121
- protected IDisposable AddObserver(TObserver observer, bool immediate, uint? priority)
122
- => AddObserverInternal(observer, immediate, priority, op => SendOperation(observer, op));
123
-
124
- private IDisposable AddObserverInternal(IObserverBase observer, bool immediate, uint? priority, Action<TOperation> sendOperation)
114
+ private IDisposable AddObserverInternal(IObserver observer, bool immediate, uint? priority, Action<TOperation> sendOperation)
125
115
  {
126
116
  if (disposed)
127
117
  throw new ObjectDisposedException(GetType().Name);
@@ -149,9 +139,6 @@ namespace ObserveThing
149
139
  public virtual IDisposable Subscribe(TObserver observer, bool immediate = default, uint? priority = default)
150
140
  => AddObserverInternal(observer, immediate, priority, op => SendOperation(observer, op));
151
141
 
152
- public virtual IDisposable Subscribe(IObserver<IOperation> observer, bool immediate = default, uint? priority = default)
153
- => AddObserverInternal(observer, immediate, priority, op => observer.OnNext(op));
154
-
155
142
  public void Dispose()
156
143
  {
157
144
  if (disposed)
@@ -5,24 +5,15 @@ using System.Linq;
5
5
 
6
6
  namespace ObserveThing
7
7
  {
8
- public interface ICollectionOp : IOperation
8
+ public struct CollectionOp<T>
9
9
  {
10
- object element { get; }
11
- uint elementId { get; }
12
- bool isRemove { get; }
10
+ public ICollectionObservable<T> source;
11
+ public T element;
12
+ public uint elementId;
13
+ public bool isRemove;
13
14
  }
14
15
 
15
- public struct CollectionOp<T> : ICollectionOp
16
- {
17
- public IObservable<IOperation> source { get; set; }
18
- public T element { get; set; }
19
- public uint elementId { get; set; }
20
- public bool isRemove { get; set; }
21
-
22
- object ICollectionOp.element => element;
23
- }
24
-
25
- public class ObservableCollection<T> : ObservableBase<ICollectionObserver<T>, CollectionOp<T>>, ICollectionObservable<T>, IEnumerable<T>
16
+ public class ObservableCollection<T> : Observable<ICollectionObserver<T>, CollectionOp<T>>, ICollectionObservable<T>, IEnumerable<T>
26
17
  {
27
18
  IEnumerator<T> IEnumerable<T>.GetEnumerator()
28
19
  => _collection.Values.GetEnumerator();
@@ -5,27 +5,16 @@ using System.Linq;
5
5
 
6
6
  namespace ObserveThing
7
7
  {
8
- public interface IDictionaryOp : IOperation
8
+ public struct DictionaryOp<TKey, TValue>
9
9
  {
10
- uint elementId { get; }
11
- object key { get; }
12
- object value { get; }
13
- bool isRemove { get; }
10
+ public IDictionaryObservable<TKey, TValue> source;
11
+ public uint elementId;
12
+ public TKey key;
13
+ public TValue value;
14
+ public bool isRemove;
14
15
  }
15
16
 
16
- public struct DictionaryOp<TKey, TValue> : IDictionaryOp
17
- {
18
- public IObservable<IOperation> source { get; set; }
19
- public uint elementId { get; set; }
20
- public TKey key { get; set; }
21
- public TValue value { get; set; }
22
- public bool isRemove { get; set; }
23
-
24
- object IDictionaryOp.key => key;
25
- object IDictionaryOp.value => value;
26
- }
27
-
28
- public class ObservableDictionary<TKey, TValue> : ObservableBase<IDictionaryObserver<TKey, TValue>, DictionaryOp<TKey, TValue>>, IDictionaryObservable<TKey, TValue>, IEnumerable<KeyValuePair<TKey, TValue>>
17
+ public class ObservableDictionary<TKey, TValue> : Observable<IDictionaryObserver<TKey, TValue>, DictionaryOp<TKey, TValue>>, IDictionaryObservable<TKey, TValue>, IEnumerable<KeyValuePair<TKey, TValue>>
29
18
  {
30
19
  public TValue this[TKey key]
31
20
  {
@@ -1,13 +1,14 @@
1
1
 
2
+ using System;
2
3
  using System.Collections.Generic;
3
4
 
4
5
  namespace ObserveThing
5
6
  {
6
- public class Observable<T> : ObservableBase<IObserver<T>, T> where T : IOperation
7
+ public class ObservableEventStream<T> : Observable<IEventStreamObserver<T>, T>, IEventStreamObservable<T>
7
8
  {
8
9
  private IInitializationOperationsProvider<T> _initializationOperationsProvider;
9
10
 
10
- public Observable(ObservationContext context, IInitializationOperationsProvider<T> initializationOperationsProvider) : base(context)
11
+ public ObservableEventStream(ObservationContext context, IInitializationOperationsProvider<T> initializationOperationsProvider) : base(context)
11
12
  {
12
13
  _initializationOperationsProvider = initializationOperationsProvider;
13
14
  }
@@ -21,10 +22,17 @@ namespace ObserveThing
21
22
  yield return op;
22
23
  }
23
24
 
24
- protected override void SendOperation(IObserver<T> observer, T operation)
25
+ protected override void SendOperation(IEventStreamObserver<T> observer, T operation)
25
26
  => observer.OnNext(operation);
26
27
 
27
28
  public void EnqueueOperation(T operation)
28
29
  => EnqueuePendingOperation(operation);
30
+
31
+ public IDisposable Subscribe(IEventStreamObserver observer, bool immediate = false, uint? priority = null)
32
+ => Subscribe(new EventStreamObserver<T>(
33
+ onNext: x => observer.OnNext(x),
34
+ onDispose: observer.OnDispose,
35
+ onError: observer.OnError
36
+ ), immediate, priority);
29
37
  }
30
38
  }
@@ -4,26 +4,16 @@ using System.Collections.Generic;
4
4
 
5
5
  namespace ObserveThing
6
6
  {
7
- public interface IListOp : IOperation
7
+ public struct ListOp<T>
8
8
  {
9
- uint elementId { get; }
10
- int index { get; }
11
- object element { get; }
12
- bool isRemove { get; }
13
- }
14
-
15
- public struct ListOp<T> : IListOp
16
- {
17
- public IObservable<IOperation> source { get; set; }
9
+ public IListObservable<T> source { get; set; }
18
10
  public int index { get; set; }
19
11
  public uint elementId { get; set; }
20
12
  public T element { get; set; }
21
13
  public bool isRemove { get; set; }
22
-
23
- object IListOp.element => element;
24
14
  }
25
15
 
26
- public class ObservableList<T> : ObservableBase<IListObserver<T>, ListOp<T>>, IListObservable<T>, IEnumerable<T>
16
+ public class ObservableList<T> : Observable<IListObserver<T>, ListOp<T>>, IListObservable<T>, IEnumerable<T>
27
17
  {
28
18
  public T this[int index]
29
19
  {
@@ -5,24 +5,15 @@ using System.Linq;
5
5
 
6
6
  namespace ObserveThing
7
7
  {
8
- public interface ISetOp : IOperation
8
+ public struct SetOp<T>
9
9
  {
10
- uint elementId { get; }
11
- object element { get; }
12
- bool isRemove { get; }
10
+ public ISetObservable<T> source;
11
+ public uint elementId;
12
+ public T element;
13
+ public bool isRemove;
13
14
  }
14
15
 
15
- public struct SetOp<T> : ISetOp
16
- {
17
- public IObservable<IOperation> source { get; set; }
18
- public uint elementId { get; set; }
19
- public T element { get; set; }
20
- public bool isRemove { get; set; }
21
-
22
- object ISetOp.element => element;
23
- }
24
-
25
- public class ObservableSet<T> : ObservableBase<ISetObserver<T>, SetOp<T>>, ISetObservable<T>, IEnumerable<T>
16
+ public class ObservableSet<T> : Observable<ISetObserver<T>, SetOp<T>>, ISetObservable<T>, IEnumerable<T>
26
17
  {
27
18
  public int count => _set.Count;
28
19
 
@@ -3,20 +3,13 @@ using System.Collections.Generic;
3
3
 
4
4
  namespace ObserveThing
5
5
  {
6
- public interface IValueOp : IOperation
6
+ public struct ValueOp<T>
7
7
  {
8
- object value { get; }
8
+ public IValueObservable<T> source;
9
+ public T value;
9
10
  }
10
11
 
11
- public struct ValueOp<T> : IValueOp
12
- {
13
- public IObservable<IOperation> source { get; set; }
14
- public T value { get; set; }
15
-
16
- object IValueOp.value => value;
17
- }
18
-
19
- public class ObservableValue<T> : ObservableBase<IValueObserver<T>, ValueOp<T>>, IValueObservable<T>
12
+ public class ObservableValue<T> : Observable<IValueObserver<T>, ValueOp<T>>, IValueObservable<T>
20
13
  {
21
14
  public T value
22
15
  {
@@ -1,5 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: 9f93943471db6f8418590f3f7da7950f
2
+ guid: e8d0c3cfd1121d2438fb3dc60ce9a8ba
3
3
  folderAsset: yes
4
4
  DefaultImporter:
5
5
  externalObjects: {}
@@ -0,0 +1,10 @@
1
+ using System;
2
+
3
+ namespace ObserveThing
4
+ {
5
+ public static class ObservationDefaults
6
+ {
7
+ public static Action<Exception> DefaultExceptionHandler = UnityEngine.Debug.LogException;
8
+ public static ObservationContext DefaultObservationContext = new ObservationContext();
9
+ }
10
+ }
@@ -0,0 +1,2 @@
1
+ fileFormatVersion: 2
2
+ guid: 023bc9be187f816429b10e4e3ff95271
@@ -3,30 +3,51 @@ using System.Collections.Generic;
3
3
 
4
4
  namespace ObserveThing
5
5
  {
6
- public static class Settings
6
+ public interface IObserver
7
7
  {
8
- public static Action<Exception> DefaultExceptionHandler = UnityEngine.Debug.LogException;
9
- public static ObservationContext DefaultObservationContext = new ObservationContext();
8
+ void OnError(Exception exc);
9
+ void OnDispose();
10
10
  }
11
11
 
12
- public interface IObserverBase
12
+ public interface IEventStreamObserver : IObserver
13
13
  {
14
- void OnError(Exception exc);
15
- void OnDispose();
14
+ void OnNext(object value);
16
15
  }
17
16
 
18
- public interface IObserver<in T> : IObserverBase where T : IOperation
17
+ public class EventStreamObserver : IValueObserver
18
+ {
19
+ private Action<object> _onNext;
20
+ private Action _onDispose;
21
+ private Action<Exception> _onError;
22
+
23
+ public EventStreamObserver(Action<object> onNext = default, Action onDispose = default, Action<Exception> onError = default)
24
+ {
25
+ _onNext = onNext;
26
+ _onDispose = onDispose;
27
+ _onError = onError;
28
+ }
29
+
30
+ public void OnNext(object value)
31
+ => _onNext?.Invoke(value);
32
+
33
+ public void OnDispose()
34
+ => _onDispose?.Invoke();
35
+
36
+ public void OnError(Exception error) => (_onError ?? ObservationDefaults.DefaultExceptionHandler)?.Invoke(error);
37
+ }
38
+
39
+ public interface IEventStreamObserver<in T> : IObserver
19
40
  {
20
41
  void OnNext(T operation);
21
42
  }
22
43
 
23
- public class Observer<T> : IObserver<T> where T : IOperation
44
+ public class EventStreamObserver<T> : IEventStreamObserver<T>
24
45
  {
25
46
  private Action<T> _onNext;
26
47
  private Action _onDispose;
27
48
  private Action<Exception> _onError;
28
49
 
29
- public Observer(Action<T> onNext = default, Action onDispose = default, Action<Exception> onError = default)
50
+ public EventStreamObserver(Action<T> onNext = default, Action onDispose = default, Action<Exception> onError = default)
30
51
  {
31
52
  _onNext = onNext;
32
53
  _onDispose = onDispose;
@@ -46,10 +67,10 @@ namespace ObserveThing
46
67
  }
47
68
 
48
69
  public void OnDispose() => _onDispose?.Invoke();
49
- public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
70
+ public void OnError(Exception error) => (_onError ?? ObservationDefaults.DefaultExceptionHandler)?.Invoke(error);
50
71
  }
51
72
 
52
- public interface IValueObserver : IObserverBase
73
+ public interface IValueObserver : IObserver
53
74
  {
54
75
  void OnNext(object value);
55
76
  }
@@ -73,10 +94,10 @@ namespace ObserveThing
73
94
  public void OnDispose()
74
95
  => _onDispose?.Invoke();
75
96
 
76
- public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
97
+ public void OnError(Exception error) => (_onError ?? ObservationDefaults.DefaultExceptionHandler)?.Invoke(error);
77
98
  }
78
99
 
79
- public interface IValueObserver<in T> : IObserverBase
100
+ public interface IValueObserver<in T> : IObserver
80
101
  {
81
102
  void OnNext(T value);
82
103
  }
@@ -100,10 +121,10 @@ namespace ObserveThing
100
121
  public void OnDispose()
101
122
  => _onDispose?.Invoke();
102
123
 
103
- public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
124
+ public void OnError(Exception error) => (_onError ?? ObservationDefaults.DefaultExceptionHandler)?.Invoke(error);
104
125
  }
105
126
 
106
- public interface ICollectionObserver : IObserverBase
127
+ public interface ICollectionObserver : IObserver
107
128
  {
108
129
  void OnAdd(uint elementId, object element);
109
130
  void OnRemove(uint elementId, object element);
@@ -133,10 +154,10 @@ namespace ObserveThing
133
154
  public void OnDispose()
134
155
  => _onDispose?.Invoke();
135
156
 
136
- public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
157
+ public void OnError(Exception error) => (_onError ?? ObservationDefaults.DefaultExceptionHandler)?.Invoke(error);
137
158
  }
138
159
 
139
- public interface ICollectionObserver<in T> : IObserverBase
160
+ public interface ICollectionObserver<in T> : IObserver
140
161
  {
141
162
  void OnAdd(uint elementId, T element);
142
163
  void OnRemove(uint elementId, T element);
@@ -166,10 +187,10 @@ namespace ObserveThing
166
187
  public void OnDispose()
167
188
  => _onDispose?.Invoke();
168
189
 
169
- public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
190
+ public void OnError(Exception error) => (_onError ?? ObservationDefaults.DefaultExceptionHandler)?.Invoke(error);
170
191
  }
171
192
 
172
- public interface IListObserver : IObserverBase
193
+ public interface IListObserver : IObserver
173
194
  {
174
195
  void OnAdd(uint elementId, int index, object element);
175
196
  void OnRemove(uint elementId, int index, object element);
@@ -199,10 +220,10 @@ namespace ObserveThing
199
220
  public void OnDispose()
200
221
  => _onDispose?.Invoke();
201
222
 
202
- public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
223
+ public void OnError(Exception error) => (_onError ?? ObservationDefaults.DefaultExceptionHandler)?.Invoke(error);
203
224
  }
204
225
 
205
- public interface IListObserver<in T> : IObserverBase
226
+ public interface IListObserver<in T> : IObserver
206
227
  {
207
228
  void OnAdd(uint elementId, int index, T element);
208
229
  void OnRemove(uint elementId, int index, T element);
@@ -232,10 +253,10 @@ namespace ObserveThing
232
253
  public void OnDispose()
233
254
  => _onDispose?.Invoke();
234
255
 
235
- public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
256
+ public void OnError(Exception error) => (_onError ?? ObservationDefaults.DefaultExceptionHandler)?.Invoke(error);
236
257
  }
237
258
 
238
- public interface ISetObserver : IObserverBase
259
+ public interface ISetObserver : IObserver
239
260
  {
240
261
  void OnAdd(uint elementId, object element);
241
262
  void OnRemove(uint elementId, object element);
@@ -265,10 +286,10 @@ namespace ObserveThing
265
286
  public void OnDispose()
266
287
  => _onDispose?.Invoke();
267
288
 
268
- public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
289
+ public void OnError(Exception error) => (_onError ?? ObservationDefaults.DefaultExceptionHandler)?.Invoke(error);
269
290
  }
270
291
 
271
- public interface ISetObserver<in T> : IObserverBase
292
+ public interface ISetObserver<in T> : IObserver
272
293
  {
273
294
  void OnAdd(uint elementId, T element);
274
295
  void OnRemove(uint elementId, T element);
@@ -298,10 +319,10 @@ namespace ObserveThing
298
319
  public void OnDispose()
299
320
  => _onDispose?.Invoke();
300
321
 
301
- public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
322
+ public void OnError(Exception error) => (_onError ?? ObservationDefaults.DefaultExceptionHandler)?.Invoke(error);
302
323
  }
303
324
 
304
- public interface IDictionaryObserver : IObserverBase
325
+ public interface IDictionaryObserver : IObserver
305
326
  {
306
327
  void OnAdd(uint elementId, KeyValuePair<object, object> kvp);
307
328
  void OnRemove(uint elementId, KeyValuePair<object, object> kvp);
@@ -331,10 +352,10 @@ namespace ObserveThing
331
352
  public void OnDispose()
332
353
  => _onDispose?.Invoke();
333
354
 
334
- public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
355
+ public void OnError(Exception error) => (_onError ?? ObservationDefaults.DefaultExceptionHandler)?.Invoke(error);
335
356
  }
336
357
 
337
- public interface IDictionaryObserver<TKey, TValue> : IObserverBase
358
+ public interface IDictionaryObserver<TKey, TValue> : IObserver
338
359
  {
339
360
  void OnAdd(uint elementId, KeyValuePair<TKey, TValue> kvp);
340
361
  void OnRemove(uint elementId, KeyValuePair<TKey, TValue> kvp);
@@ -364,40 +385,6 @@ namespace ObserveThing
364
385
  public void OnDispose()
365
386
  => _onDispose?.Invoke();
366
387
 
367
- public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
368
- }
369
-
370
- public interface IBatchObserver<in T> : IObserverBase where T : IOperation
371
- {
372
- void OnNext(IReadOnlyList<T> operations);
373
- }
374
-
375
- public class BatchObserver<T> : IBatchObserver<T> where T : IOperation
376
- {
377
- private Action<IReadOnlyList<T>> _onNext;
378
- private Action _onDispose;
379
- private Action<Exception> _onError;
380
-
381
- public BatchObserver(Action<IReadOnlyList<T>> onNext = default, Action onDispose = default, Action<Exception> onError = default)
382
- {
383
- _onNext = onNext;
384
- _onDispose = onDispose;
385
- _onError = onError;
386
- }
387
-
388
- public void OnNext(IReadOnlyList<T> args)
389
- {
390
- try
391
- {
392
- _onNext?.Invoke(args);
393
- }
394
- catch (Exception exc)
395
- {
396
- OnError(exc);
397
- }
398
- }
399
-
400
- public void OnDispose() => _onDispose?.Invoke();
401
- public void OnError(Exception error) => (_onError ?? Settings.DefaultExceptionHandler)?.Invoke(error);
388
+ public void OnError(Exception error) => (_onError ?? ObservationDefaults.DefaultExceptionHandler)?.Invoke(error);
402
389
  }
403
390
  }