-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'decouple-reactive-data'
- Loading branch information
Showing
19 changed files
with
875 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace EcsRx.MicroRx.Disposables | ||
{ | ||
public interface ICancelable : IDisposable | ||
{ | ||
bool IsDisposed { get; } | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/EcsRx.MicroRx/Disposables/SingleAssignmentDisposable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
|
||
namespace EcsRx.MicroRx.Disposables | ||
{ | ||
public class SingleAssignmentDisposable : IDisposable, ICancelable | ||
{ | ||
readonly object gate = new object(); | ||
IDisposable current; | ||
bool disposed; | ||
|
||
public bool IsDisposed { get { lock (gate) { return disposed; } } } | ||
|
||
public IDisposable Disposable | ||
{ | ||
get | ||
{ | ||
return current; | ||
} | ||
set | ||
{ | ||
var old = default(IDisposable); | ||
bool alreadyDisposed; | ||
lock (gate) | ||
{ | ||
alreadyDisposed = disposed; | ||
old = current; | ||
if (!alreadyDisposed) | ||
{ | ||
if (value == null) return; | ||
current = value; | ||
} | ||
} | ||
|
||
if (alreadyDisposed && value != null) | ||
{ | ||
value.Dispose(); | ||
return; | ||
} | ||
|
||
if (old != null) throw new InvalidOperationException("Disposable is already set"); | ||
} | ||
} | ||
|
||
|
||
public void Dispose() | ||
{ | ||
IDisposable old = null; | ||
|
||
lock (gate) | ||
{ | ||
if (!disposed) | ||
{ | ||
disposed = true; | ||
old = current; | ||
current = null; | ||
} | ||
} | ||
|
||
if (old != null) old.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using EcsRx.MicroRx.Disposables; | ||
|
||
namespace EcsRx.MicroRx.Operators | ||
{ | ||
public class ImmutableEmptyObservable<T> : IObservable<T> | ||
{ | ||
public static ImmutableEmptyObservable<T> Instance = new ImmutableEmptyObservable<T>(); | ||
|
||
ImmutableEmptyObservable() | ||
{ | ||
|
||
} | ||
|
||
public IDisposable Subscribe(IObserver<T> observer) | ||
{ | ||
observer.OnCompleted(); | ||
return Disposable.Empty; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using EcsRx.MicroRx.Disposables; | ||
|
||
namespace EcsRx.MicroRx.Operators | ||
{ | ||
public abstract class OperatorObservableBase<T> : IObservable<T> | ||
{ | ||
readonly bool isRequiredSubscribeOnCurrentThread; | ||
|
||
public OperatorObservableBase(bool isRequiredSubscribeOnCurrentThread) | ||
{ | ||
this.isRequiredSubscribeOnCurrentThread = isRequiredSubscribeOnCurrentThread; | ||
} | ||
|
||
public bool IsRequiredSubscribeOnCurrentThread() | ||
{ | ||
return isRequiredSubscribeOnCurrentThread; | ||
} | ||
|
||
public IDisposable Subscribe(IObserver<T> observer) | ||
{ | ||
var subscription = new SingleAssignmentDisposable(); | ||
subscription.Disposable = SubscribeCore(observer, subscription); | ||
return subscription; | ||
} | ||
|
||
protected abstract IDisposable SubscribeCore(IObserver<T> observer, IDisposable cancel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
|
||
namespace EcsRx.MicroRx | ||
{ | ||
[Serializable] | ||
public struct Unit : IEquatable<Unit> | ||
{ | ||
static readonly Unit @default = new Unit(); | ||
|
||
public static Unit Default { get { return @default; } } | ||
|
||
public static bool operator ==(Unit first, Unit second) | ||
{ | ||
return true; | ||
} | ||
|
||
public static bool operator !=(Unit first, Unit second) | ||
{ | ||
return false; | ||
} | ||
|
||
public bool Equals(Unit other) | ||
{ | ||
return true; | ||
} | ||
public override bool Equals(object obj) | ||
{ | ||
return obj is Unit; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return 0; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return "()"; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/EcsRx.ReactiveData/Collections/IReadOnlyReactiveCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/EcsRx.ReactiveData/Dictionaries/IReadOnlyReactiveDictionary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/EcsRx.ReactiveData/Extensions/IObservableExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
|
||
namespace EcsRx.ReactiveData.Extensions | ||
{ | ||
public static class IObservableExtensions | ||
{ | ||
public static IReactiveProperty<T> ToReactiveProperty<T>(this IObservable<T> source) | ||
{ | ||
return new ReactiveProperty<T>(source); | ||
} | ||
|
||
public static IReactiveProperty<T> ToReactiveProperty<T>(this IObservable<T> source, T initialValue) | ||
{ | ||
return new ReactiveProperty<T>(source, initialValue); | ||
} | ||
|
||
public static IReadOnlyReactiveProperty<T> ToReadOnlyReactiveProperty<T>(this IObservable<T> source) | ||
{ | ||
return new ReactiveProperty<T>(source); | ||
} | ||
|
||
public static IReadOnlyReactiveProperty<T> ToReadOnlyReactiveProperty<T>(this IObservable<T> source, T initialValue) | ||
{ | ||
return new ReactiveProperty<T>(source, initialValue); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.