架构大更
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace UniRx
|
||||
{
|
||||
@@ -8,4 +6,4 @@ namespace UniRx
|
||||
{
|
||||
bool IsDisposed { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,13 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace UniRx
|
||||
{
|
||||
public sealed class MultipleAssignmentDisposable : IDisposable, ICancelable
|
||||
{
|
||||
static readonly BooleanDisposable True = new BooleanDisposable(true);
|
||||
private static readonly BooleanDisposable True = new(true);
|
||||
private IDisposable current;
|
||||
|
||||
object gate = new object();
|
||||
IDisposable current;
|
||||
|
||||
public bool IsDisposed
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
return current == True;
|
||||
}
|
||||
}
|
||||
}
|
||||
private readonly object gate = new();
|
||||
|
||||
public IDisposable Disposable
|
||||
{
|
||||
@@ -27,7 +15,7 @@ namespace UniRx
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
return (current == True)
|
||||
return current == True
|
||||
? UniRx.Disposable.Empty
|
||||
: current;
|
||||
}
|
||||
@@ -37,15 +25,21 @@ namespace UniRx
|
||||
var shouldDispose = false;
|
||||
lock (gate)
|
||||
{
|
||||
shouldDispose = (current == True);
|
||||
if (!shouldDispose)
|
||||
{
|
||||
current = value;
|
||||
}
|
||||
shouldDispose = current == True;
|
||||
if (!shouldDispose) current = value;
|
||||
}
|
||||
if (shouldDispose && value != null)
|
||||
|
||||
if (shouldDispose && value != null) value.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDisposed
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
value.Dispose();
|
||||
return current == True;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System;
|
||||
|
||||
namespace UniRx
|
||||
{
|
||||
/// <summary>
|
||||
/// Notify boolean flag.
|
||||
/// Notify boolean flag.
|
||||
/// </summary>
|
||||
public class BooleanNotifier : IObservable<bool>
|
||||
{
|
||||
readonly Subject<bool> boolTrigger = new Subject<bool>();
|
||||
private readonly Subject<bool> boolTrigger = new();
|
||||
|
||||
private bool boolValue;
|
||||
|
||||
/// <summary>
|
||||
/// Setup initial flag.
|
||||
/// </summary>
|
||||
public BooleanNotifier(bool initialValue = false)
|
||||
{
|
||||
Value = initialValue;
|
||||
}
|
||||
|
||||
bool boolValue;
|
||||
/// <summary>Current flag value</summary>
|
||||
public bool Value
|
||||
{
|
||||
get { return boolValue; }
|
||||
get => boolValue;
|
||||
set
|
||||
{
|
||||
boolValue = value;
|
||||
@@ -23,51 +30,37 @@ namespace UniRx
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setup initial flag.
|
||||
/// </summary>
|
||||
public BooleanNotifier(bool initialValue = false)
|
||||
{
|
||||
this.Value = initialValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set and raise true if current value isn't true.
|
||||
/// </summary>
|
||||
public void TurnOn()
|
||||
{
|
||||
if (Value != true)
|
||||
{
|
||||
Value = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set and raise false if current value isn't false.
|
||||
/// </summary>
|
||||
public void TurnOff()
|
||||
{
|
||||
if (Value != false)
|
||||
{
|
||||
Value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set and raise reverse value.
|
||||
/// </summary>
|
||||
public void SwitchValue()
|
||||
{
|
||||
Value = !Value;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe observer.
|
||||
/// Subscribe observer.
|
||||
/// </summary>
|
||||
public IDisposable Subscribe(IObserver<bool> observer)
|
||||
{
|
||||
return boolTrigger.Subscribe(observer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set and raise true if current value isn't true.
|
||||
/// </summary>
|
||||
public void TurnOn()
|
||||
{
|
||||
if (!Value) Value = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set and raise false if current value isn't false.
|
||||
/// </summary>
|
||||
public void TurnOff()
|
||||
{
|
||||
if (Value) Value = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set and raise reverse value.
|
||||
/// </summary>
|
||||
public void SwitchValue()
|
||||
{
|
||||
Value = !Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using UniRx.Operators;
|
||||
|
||||
namespace UniRx.Operators
|
||||
{
|
||||
internal class AggregateObservable<TSource> : OperatorObservableBase<TSource>
|
||||
{
|
||||
readonly IObservable<TSource> source;
|
||||
readonly Func<TSource, TSource, TSource> accumulator;
|
||||
private readonly Func<TSource, TSource, TSource> accumulator;
|
||||
private readonly IObservable<TSource> source;
|
||||
|
||||
public AggregateObservable(IObservable<TSource> source, Func<TSource, TSource, TSource> accumulator)
|
||||
: base(source.IsRequiredSubscribeOnCurrentThread())
|
||||
@@ -20,16 +19,17 @@ namespace UniRx.Operators
|
||||
return source.Subscribe(new Aggregate(this, observer, cancel));
|
||||
}
|
||||
|
||||
class Aggregate : OperatorObserverBase<TSource, TSource>
|
||||
private class Aggregate : OperatorObserverBase<TSource, TSource>
|
||||
{
|
||||
readonly AggregateObservable<TSource> parent;
|
||||
TSource accumulation;
|
||||
bool seenValue;
|
||||
private readonly AggregateObservable<TSource> parent;
|
||||
private TSource accumulation;
|
||||
private bool seenValue;
|
||||
|
||||
public Aggregate(AggregateObservable<TSource> parent, IObserver<TSource> observer, IDisposable cancel) : base(observer, cancel)
|
||||
public Aggregate(AggregateObservable<TSource> parent, IObserver<TSource> observer, IDisposable cancel) :
|
||||
base(observer, cancel)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.seenValue = false;
|
||||
seenValue = false;
|
||||
}
|
||||
|
||||
public override void OnNext(TSource value)
|
||||
@@ -47,40 +47,55 @@ namespace UniRx.Operators
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
try { observer.OnError(ex); }
|
||||
finally { Dispose(); }
|
||||
return;
|
||||
try
|
||||
{
|
||||
observer.OnError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
{
|
||||
if (!seenValue)
|
||||
{
|
||||
throw new InvalidOperationException("Sequence contains no elements.");
|
||||
}
|
||||
if (!seenValue) throw new InvalidOperationException("Sequence contains no elements.");
|
||||
|
||||
observer.OnNext(accumulation);
|
||||
try { observer.OnCompleted(); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class AggregateObservable<TSource, TAccumulate> : OperatorObservableBase<TAccumulate>
|
||||
{
|
||||
readonly IObservable<TSource> source;
|
||||
readonly TAccumulate seed;
|
||||
readonly Func<TAccumulate, TSource, TAccumulate> accumulator;
|
||||
private readonly Func<TAccumulate, TSource, TAccumulate> accumulator;
|
||||
private readonly TAccumulate seed;
|
||||
private readonly IObservable<TSource> source;
|
||||
|
||||
public AggregateObservable(IObservable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator)
|
||||
public AggregateObservable(IObservable<TSource> source, TAccumulate seed,
|
||||
Func<TAccumulate, TSource, TAccumulate> accumulator)
|
||||
: base(source.IsRequiredSubscribeOnCurrentThread())
|
||||
{
|
||||
this.source = source;
|
||||
@@ -93,15 +108,16 @@ namespace UniRx.Operators
|
||||
return source.Subscribe(new Aggregate(this, observer, cancel));
|
||||
}
|
||||
|
||||
class Aggregate : OperatorObserverBase<TSource, TAccumulate>
|
||||
private class Aggregate : OperatorObserverBase<TSource, TAccumulate>
|
||||
{
|
||||
readonly AggregateObservable<TSource, TAccumulate> parent;
|
||||
TAccumulate accumulation;
|
||||
private readonly AggregateObservable<TSource, TAccumulate> parent;
|
||||
private TAccumulate accumulation;
|
||||
|
||||
public Aggregate(AggregateObservable<TSource, TAccumulate> parent, IObserver<TAccumulate> observer, IDisposable cancel) : base(observer, cancel)
|
||||
public Aggregate(AggregateObservable<TSource, TAccumulate> parent, IObserver<TAccumulate> observer,
|
||||
IDisposable cancel) : base(observer, cancel)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.accumulation = parent.seed;
|
||||
accumulation = parent.seed;
|
||||
}
|
||||
|
||||
public override void OnNext(TSource value)
|
||||
@@ -112,35 +128,53 @@ namespace UniRx.Operators
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
try { observer.OnError(ex); }
|
||||
finally { Dispose(); }
|
||||
return;
|
||||
try
|
||||
{
|
||||
observer.OnError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
{
|
||||
observer.OnNext(accumulation);
|
||||
try { observer.OnCompleted(); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class AggregateObservable<TSource, TAccumulate, TResult> : OperatorObservableBase<TResult>
|
||||
{
|
||||
readonly IObservable<TSource> source;
|
||||
readonly TAccumulate seed;
|
||||
readonly Func<TAccumulate, TSource, TAccumulate> accumulator;
|
||||
readonly Func<TAccumulate, TResult> resultSelector;
|
||||
private readonly Func<TAccumulate, TSource, TAccumulate> accumulator;
|
||||
private readonly Func<TAccumulate, TResult> resultSelector;
|
||||
private readonly TAccumulate seed;
|
||||
private readonly IObservable<TSource> source;
|
||||
|
||||
public AggregateObservable(IObservable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, Func<TAccumulate, TResult> resultSelector)
|
||||
public AggregateObservable(IObservable<TSource> source, TAccumulate seed,
|
||||
Func<TAccumulate, TSource, TAccumulate> accumulator, Func<TAccumulate, TResult> resultSelector)
|
||||
: base(source.IsRequiredSubscribeOnCurrentThread())
|
||||
{
|
||||
this.source = source;
|
||||
@@ -154,15 +188,16 @@ namespace UniRx.Operators
|
||||
return source.Subscribe(new Aggregate(this, observer, cancel));
|
||||
}
|
||||
|
||||
class Aggregate : OperatorObserverBase<TSource, TResult>
|
||||
private class Aggregate : OperatorObserverBase<TSource, TResult>
|
||||
{
|
||||
readonly AggregateObservable<TSource, TAccumulate, TResult> parent;
|
||||
TAccumulate accumulation;
|
||||
private readonly AggregateObservable<TSource, TAccumulate, TResult> parent;
|
||||
private TAccumulate accumulation;
|
||||
|
||||
public Aggregate(AggregateObservable<TSource, TAccumulate, TResult> parent, IObserver<TResult> observer, IDisposable cancel) : base(observer, cancel)
|
||||
public Aggregate(AggregateObservable<TSource, TAccumulate, TResult> parent, IObserver<TResult> observer,
|
||||
IDisposable cancel) : base(observer, cancel)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.accumulation = parent.seed;
|
||||
accumulation = parent.seed;
|
||||
}
|
||||
|
||||
public override void OnNext(TSource value)
|
||||
@@ -173,16 +208,27 @@ namespace UniRx.Operators
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
try { observer.OnError(ex); }
|
||||
finally { Dispose(); }
|
||||
return;
|
||||
try
|
||||
{
|
||||
observer.OnError(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
@@ -199,8 +245,14 @@ namespace UniRx.Operators
|
||||
}
|
||||
|
||||
observer.OnNext(result);
|
||||
try { observer.OnCompleted(); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace UniRx.Operators
|
||||
{
|
||||
internal class ContinueWithObservable<TSource, TResult> : OperatorObservableBase<TResult>
|
||||
{
|
||||
readonly IObservable<TSource> source;
|
||||
readonly Func<TSource, IObservable<TResult>> selector;
|
||||
private readonly Func<TSource, IObservable<TResult>> selector;
|
||||
private readonly IObservable<TSource> source;
|
||||
|
||||
public ContinueWithObservable(IObservable<TSource> source, Func<TSource, IObservable<TResult>> selector)
|
||||
: base(source.IsRequiredSubscribeOnCurrentThread())
|
||||
@@ -19,15 +19,16 @@ namespace UniRx.Operators
|
||||
return new ContinueWith(this, observer, cancel).Run();
|
||||
}
|
||||
|
||||
class ContinueWith : OperatorObserverBase<TSource, TResult>
|
||||
private class ContinueWith : OperatorObserverBase<TSource, TResult>
|
||||
{
|
||||
readonly ContinueWithObservable<TSource, TResult> parent;
|
||||
readonly SerialDisposable serialDisposable = new SerialDisposable();
|
||||
private readonly ContinueWithObservable<TSource, TResult> parent;
|
||||
private readonly SerialDisposable serialDisposable = new();
|
||||
private TSource lastValue;
|
||||
|
||||
bool seenValue;
|
||||
TSource lastValue;
|
||||
private bool seenValue;
|
||||
|
||||
public ContinueWith(ContinueWithObservable<TSource, TResult> parent, IObserver<TResult> observer, IDisposable cancel) : base(observer, cancel)
|
||||
public ContinueWith(ContinueWithObservable<TSource, TResult> parent, IObserver<TResult> observer,
|
||||
IDisposable cancel) : base(observer, cancel)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
@@ -43,13 +44,22 @@ namespace UniRx.Operators
|
||||
|
||||
public override void OnNext(TSource value)
|
||||
{
|
||||
this.seenValue = true;
|
||||
this.lastValue = value;
|
||||
seenValue = true;
|
||||
lastValue = value;
|
||||
}
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); } finally { Dispose(); };
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
@@ -57,19 +67,28 @@ namespace UniRx.Operators
|
||||
if (seenValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var v = parent.selector(lastValue);
|
||||
// dispose source subscription
|
||||
serialDisposable.Disposable = v.Subscribe(observer);
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
OnError(error);
|
||||
}
|
||||
{
|
||||
var v = parent.selector(lastValue);
|
||||
// dispose source subscription
|
||||
serialDisposable.Disposable = v.Subscribe(observer);
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
OnError(error);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try { observer.OnCompleted(); } finally { Dispose(); };
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace UniRx.Operators
|
||||
{
|
||||
internal class DeferObservable<T> : OperatorObservableBase<T>
|
||||
{
|
||||
readonly Func<IObservable<T>> observableFactory;
|
||||
private readonly Func<IObservable<T>> observableFactory;
|
||||
|
||||
public DeferObservable(Func<IObservable<T>> observableFactory)
|
||||
: base(false)
|
||||
@@ -29,7 +29,7 @@ namespace UniRx.Operators
|
||||
return source.Subscribe(observer);
|
||||
}
|
||||
|
||||
class Defer : OperatorObserverBase<T, T>
|
||||
private class Defer : OperatorObserverBase<T, T>
|
||||
{
|
||||
public Defer(IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
|
||||
{
|
||||
@@ -39,7 +39,7 @@ namespace UniRx.Operators
|
||||
{
|
||||
try
|
||||
{
|
||||
base.observer.OnNext(value);
|
||||
observer.OnNext(value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -50,14 +50,26 @@ namespace UniRx.Operators
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
{
|
||||
try { observer.OnCompleted(); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace UniRx.Operators
|
||||
{
|
||||
internal class MaterializeObservable<T> : OperatorObservableBase<Notification<T>>
|
||||
{
|
||||
readonly IObservable<T> source;
|
||||
private readonly IObservable<T> source;
|
||||
|
||||
public MaterializeObservable(IObservable<T> source)
|
||||
: base(source.IsRequiredSubscribeOnCurrentThread())
|
||||
@@ -17,9 +17,9 @@ namespace UniRx.Operators
|
||||
return new Materialize(this, observer, cancel).Run();
|
||||
}
|
||||
|
||||
class Materialize : OperatorObserverBase<T, Notification<T>>
|
||||
private class Materialize : OperatorObserverBase<T, Notification<T>>
|
||||
{
|
||||
readonly MaterializeObservable<T> parent;
|
||||
private readonly MaterializeObservable<T> parent;
|
||||
|
||||
public Materialize(MaterializeObservable<T> parent, IObserver<Notification<T>> observer, IDisposable cancel)
|
||||
: base(observer, cancel)
|
||||
@@ -40,13 +40,27 @@ namespace UniRx.Operators
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
observer.OnNext(Notification.CreateOnError<T>(error));
|
||||
try { observer.OnCompleted(); } finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
{
|
||||
observer.OnNext(Notification.CreateOnCompleted<T>());
|
||||
try { observer.OnCompleted(); } finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using UniRx.Operators;
|
||||
|
||||
namespace UniRx.Operators
|
||||
{
|
||||
internal class RefCountObservable<T> : OperatorObservableBase<T>
|
||||
{
|
||||
readonly IConnectableObservable<T> source;
|
||||
readonly object gate = new object();
|
||||
int refCount = 0;
|
||||
IDisposable connection;
|
||||
private readonly object gate = new();
|
||||
private readonly IConnectableObservable<T> source;
|
||||
private IDisposable connection;
|
||||
private int refCount;
|
||||
|
||||
public RefCountObservable(IConnectableObservable<T> source)
|
||||
: base(source.IsRequiredSubscribeOnCurrentThread())
|
||||
@@ -21,11 +20,12 @@ namespace UniRx.Operators
|
||||
return new RefCount(this, observer, cancel).Run();
|
||||
}
|
||||
|
||||
class RefCount : OperatorObserverBase<T, T>
|
||||
private class RefCount : OperatorObserverBase<T, T>
|
||||
{
|
||||
readonly RefCountObservable<T> parent;
|
||||
private readonly RefCountObservable<T> parent;
|
||||
|
||||
public RefCount(RefCountObservable<T> parent, IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
|
||||
public RefCount(RefCountObservable<T> parent, IObserver<T> observer, IDisposable cancel) : base(observer,
|
||||
cancel)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
@@ -36,10 +36,7 @@ namespace UniRx.Operators
|
||||
|
||||
lock (parent.gate)
|
||||
{
|
||||
if (++parent.refCount == 1)
|
||||
{
|
||||
parent.connection = parent.source.Connect();
|
||||
}
|
||||
if (++parent.refCount == 1) parent.connection = parent.source.Connect();
|
||||
}
|
||||
|
||||
return Disposable.Create(() =>
|
||||
@@ -48,29 +45,38 @@ namespace UniRx.Operators
|
||||
|
||||
lock (parent.gate)
|
||||
{
|
||||
if (--parent.refCount == 0)
|
||||
{
|
||||
parent.connection.Dispose();
|
||||
}
|
||||
if (--parent.refCount == 0) parent.connection.Dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnNext(T value)
|
||||
{
|
||||
base.observer.OnNext(value);
|
||||
observer.OnNext(value);
|
||||
}
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
{
|
||||
try { observer.OnCompleted(); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ namespace UniRx.Operators
|
||||
{
|
||||
internal class RepeatObservable<T> : OperatorObservableBase<T>
|
||||
{
|
||||
readonly T value;
|
||||
readonly int? repeatCount;
|
||||
readonly IScheduler scheduler;
|
||||
private readonly int? repeatCount;
|
||||
private readonly IScheduler scheduler;
|
||||
private readonly T value;
|
||||
|
||||
public RepeatObservable(T value, int? repeatCount, IScheduler scheduler)
|
||||
: base(scheduler == Scheduler.CurrentThread)
|
||||
@@ -21,49 +21,40 @@ namespace UniRx.Operators
|
||||
observer = new Repeat(observer, cancel);
|
||||
|
||||
if (repeatCount == null)
|
||||
{
|
||||
return scheduler.Schedule((Action self) =>
|
||||
return scheduler.Schedule(self =>
|
||||
{
|
||||
observer.OnNext(value);
|
||||
self();
|
||||
});
|
||||
}
|
||||
else
|
||||
|
||||
if (scheduler == Scheduler.Immediate)
|
||||
{
|
||||
if (scheduler == Scheduler.Immediate)
|
||||
{
|
||||
var count = this.repeatCount.Value;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
observer.OnNext(value);
|
||||
}
|
||||
observer.OnCompleted();
|
||||
return Disposable.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
var currentCount = this.repeatCount.Value;
|
||||
return scheduler.Schedule((Action self) =>
|
||||
{
|
||||
if (currentCount > 0)
|
||||
{
|
||||
observer.OnNext(value);
|
||||
currentCount--;
|
||||
}
|
||||
|
||||
if (currentCount == 0)
|
||||
{
|
||||
observer.OnCompleted();
|
||||
return;
|
||||
}
|
||||
|
||||
self();
|
||||
});
|
||||
}
|
||||
var count = repeatCount.Value;
|
||||
for (var i = 0; i < count; i++) observer.OnNext(value);
|
||||
observer.OnCompleted();
|
||||
return Disposable.Empty;
|
||||
}
|
||||
|
||||
var currentCount = repeatCount.Value;
|
||||
return scheduler.Schedule(self =>
|
||||
{
|
||||
if (currentCount > 0)
|
||||
{
|
||||
observer.OnNext(value);
|
||||
currentCount--;
|
||||
}
|
||||
|
||||
if (currentCount == 0)
|
||||
{
|
||||
observer.OnCompleted();
|
||||
return;
|
||||
}
|
||||
|
||||
self();
|
||||
});
|
||||
}
|
||||
|
||||
class Repeat : OperatorObserverBase<T, T>
|
||||
private class Repeat : OperatorObserverBase<T, T>
|
||||
{
|
||||
public Repeat(IObserver<T> observer, IDisposable cancel)
|
||||
: base(observer, cancel)
|
||||
@@ -74,7 +65,7 @@ namespace UniRx.Operators
|
||||
{
|
||||
try
|
||||
{
|
||||
base.observer.OnNext(value);
|
||||
observer.OnNext(value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -85,14 +76,26 @@ namespace UniRx.Operators
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
{
|
||||
try { observer.OnCompleted(); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using UniRx.Operators;
|
||||
|
||||
namespace UniRx.Operators
|
||||
{
|
||||
internal class SkipObservable<T> : OperatorObservableBase<T>
|
||||
{
|
||||
readonly IObservable<T> source;
|
||||
readonly int count;
|
||||
readonly TimeSpan duration;
|
||||
private readonly int count;
|
||||
private readonly TimeSpan duration;
|
||||
internal readonly IScheduler scheduler; // public for optimization check
|
||||
private readonly IObservable<T> source;
|
||||
|
||||
public SkipObservable(IObservable<T> source, int count)
|
||||
: base(source.IsRequiredSubscribeOnCurrentThread())
|
||||
@@ -44,59 +43,64 @@ namespace UniRx.Operators
|
||||
// xs.Skip(2s) = 2s
|
||||
// xs.Skip(2s).Skip(3s) = 3s
|
||||
|
||||
return (duration <= this.duration)
|
||||
return duration <= this.duration
|
||||
? this
|
||||
: new SkipObservable<T>(source, duration, scheduler);
|
||||
}
|
||||
|
||||
protected override IDisposable SubscribeCore(IObserver<T> observer, IDisposable cancel)
|
||||
{
|
||||
if (scheduler == null)
|
||||
{
|
||||
return source.Subscribe(new Skip(this, observer, cancel));
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Skip_(this, observer, cancel).Run();
|
||||
}
|
||||
if (scheduler == null) return source.Subscribe(new Skip(this, observer, cancel));
|
||||
|
||||
return new Skip_(this, observer, cancel).Run();
|
||||
}
|
||||
|
||||
class Skip : OperatorObserverBase<T, T>
|
||||
private class Skip : OperatorObserverBase<T, T>
|
||||
{
|
||||
int remaining;
|
||||
private int remaining;
|
||||
|
||||
public Skip(SkipObservable<T> parent, IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
|
||||
{
|
||||
this.remaining = parent.count;
|
||||
remaining = parent.count;
|
||||
}
|
||||
|
||||
public override void OnNext(T value)
|
||||
{
|
||||
if (remaining <= 0)
|
||||
{
|
||||
base.observer.OnNext(value);
|
||||
}
|
||||
observer.OnNext(value);
|
||||
else
|
||||
{
|
||||
remaining--;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); } finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
{
|
||||
try { observer.OnCompleted(); } finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Skip_ : OperatorObserverBase<T, T>
|
||||
private class Skip_ : OperatorObserverBase<T, T>
|
||||
{
|
||||
readonly SkipObservable<T> parent;
|
||||
volatile bool open;
|
||||
private readonly SkipObservable<T> parent;
|
||||
private volatile bool open;
|
||||
|
||||
public Skip_(SkipObservable<T> parent, IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
|
||||
{
|
||||
@@ -111,27 +115,42 @@ namespace UniRx.Operators
|
||||
return StableCompositeDisposable.Create(d1, d2);
|
||||
}
|
||||
|
||||
void Tick()
|
||||
private void Tick()
|
||||
{
|
||||
open = true;
|
||||
}
|
||||
|
||||
public override void OnNext(T value)
|
||||
{
|
||||
if (open)
|
||||
{
|
||||
base.observer.OnNext(value);
|
||||
}
|
||||
if (open) observer.OnNext(value);
|
||||
}
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); } finally { Dispose(); };
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
{
|
||||
try { observer.OnCompleted(); } finally { Dispose(); };
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace UniRx.Operators
|
||||
{
|
||||
internal class SynchronizedObserver<T> : IObserver<T>
|
||||
{
|
||||
readonly IObserver<T> observer;
|
||||
readonly object gate;
|
||||
private readonly object gate;
|
||||
private readonly IObserver<T> observer;
|
||||
|
||||
public SynchronizedObserver(IObserver<T> observer, object gate)
|
||||
{
|
||||
@@ -37,4 +37,4 @@ namespace UniRx.Operators
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using UniRx.Operators;
|
||||
|
||||
namespace UniRx.Operators
|
||||
{
|
||||
internal class TakeObservable<T> : OperatorObservableBase<T>
|
||||
{
|
||||
readonly IObservable<T> source;
|
||||
readonly int count;
|
||||
readonly TimeSpan duration;
|
||||
private readonly int count;
|
||||
private readonly TimeSpan duration;
|
||||
internal readonly IScheduler scheduler; // public for optimization check
|
||||
private readonly IObservable<T> source;
|
||||
|
||||
public TakeObservable(IObservable<T> source, int count)
|
||||
: base(source.IsRequiredSubscribeOnCurrentThread())
|
||||
@@ -34,7 +33,7 @@ namespace UniRx.Operators
|
||||
// xs.Take(5).Take(3) = 3 | xs.Take(3).Take(5) = 3
|
||||
|
||||
// use minimum one
|
||||
return (this.count <= count)
|
||||
return this.count <= count
|
||||
? this
|
||||
: new TakeObservable<T>(source, count);
|
||||
}
|
||||
@@ -46,30 +45,25 @@ namespace UniRx.Operators
|
||||
// xs.Take(5s).Take(3s) = 3s | xs.Take(3s).Take(5s) = 3s
|
||||
|
||||
// use minimum one
|
||||
return (this.duration <= duration)
|
||||
return this.duration <= duration
|
||||
? this
|
||||
: new TakeObservable<T>(source, duration, scheduler);
|
||||
}
|
||||
|
||||
protected override IDisposable SubscribeCore(IObserver<T> observer, IDisposable cancel)
|
||||
{
|
||||
if (scheduler == null)
|
||||
{
|
||||
return source.Subscribe(new Take(this, observer, cancel));
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Take_(this, observer, cancel).Run();
|
||||
}
|
||||
if (scheduler == null) return source.Subscribe(new Take(this, observer, cancel));
|
||||
|
||||
return new Take_(this, observer, cancel).Run();
|
||||
}
|
||||
|
||||
class Take : OperatorObserverBase<T, T>
|
||||
private class Take : OperatorObserverBase<T, T>
|
||||
{
|
||||
int rest;
|
||||
private int rest;
|
||||
|
||||
public Take(TakeObservable<T> parent, IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
|
||||
{
|
||||
this.rest = parent.count;
|
||||
rest = parent.count;
|
||||
}
|
||||
|
||||
public override void OnNext(T value)
|
||||
@@ -77,29 +71,52 @@ namespace UniRx.Operators
|
||||
if (rest > 0)
|
||||
{
|
||||
rest -= 1;
|
||||
base.observer.OnNext(value);
|
||||
observer.OnNext(value);
|
||||
if (rest == 0)
|
||||
{
|
||||
try { observer.OnCompleted(); } finally { Dispose(); };
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); } finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
{
|
||||
try { observer.OnCompleted(); } finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Take_ : OperatorObserverBase<T, T>
|
||||
private class Take_ : OperatorObserverBase<T, T>
|
||||
{
|
||||
readonly TakeObservable<T> parent;
|
||||
readonly object gate = new object();
|
||||
private readonly object gate = new();
|
||||
private readonly TakeObservable<T> parent;
|
||||
|
||||
public Take_(TakeObservable<T> parent, IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
|
||||
{
|
||||
@@ -114,11 +131,20 @@ namespace UniRx.Operators
|
||||
return StableCompositeDisposable.Create(d1, d2);
|
||||
}
|
||||
|
||||
void Tick()
|
||||
private void Tick()
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
try { observer.OnCompleted(); } finally { Dispose(); };
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +152,7 @@ namespace UniRx.Operators
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
base.observer.OnNext(value);
|
||||
observer.OnNext(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +160,16 @@ namespace UniRx.Operators
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
try { observer.OnError(error); } finally { Dispose(); };
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +177,16 @@ namespace UniRx.Operators
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
try { observer.OnCompleted(); } finally { Dispose(); };
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,15 @@ namespace UniRx.Operators
|
||||
{
|
||||
internal class TimerObservable : OperatorObservableBase<long>
|
||||
{
|
||||
readonly DateTimeOffset? dueTimeA;
|
||||
readonly TimeSpan? dueTimeB;
|
||||
readonly TimeSpan? period;
|
||||
readonly IScheduler scheduler;
|
||||
private readonly DateTimeOffset? dueTimeA;
|
||||
private readonly TimeSpan? dueTimeB;
|
||||
private readonly TimeSpan? period;
|
||||
private readonly IScheduler scheduler;
|
||||
|
||||
public TimerObservable(DateTimeOffset dueTime, TimeSpan? period, IScheduler scheduler)
|
||||
: base(scheduler == Scheduler.CurrentThread)
|
||||
{
|
||||
this.dueTimeA = dueTime;
|
||||
dueTimeA = dueTime;
|
||||
this.period = period;
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
@@ -20,7 +20,7 @@ namespace UniRx.Operators
|
||||
public TimerObservable(TimeSpan dueTime, TimeSpan? period, IScheduler scheduler)
|
||||
: base(scheduler == Scheduler.CurrentThread)
|
||||
{
|
||||
this.dueTimeB = dueTime;
|
||||
dueTimeB = dueTime;
|
||||
this.period = period;
|
||||
this.scheduler = scheduler;
|
||||
}
|
||||
@@ -29,61 +29,54 @@ namespace UniRx.Operators
|
||||
{
|
||||
var timerObserver = new Timer(observer, cancel);
|
||||
|
||||
var dueTime = (dueTimeA != null)
|
||||
var dueTime = dueTimeA != null
|
||||
? dueTimeA.Value - scheduler.Now
|
||||
: dueTimeB.Value;
|
||||
|
||||
// one-shot
|
||||
if (period == null)
|
||||
{
|
||||
return scheduler.Schedule(Scheduler.Normalize(dueTime), () =>
|
||||
{
|
||||
timerObserver.OnNext();
|
||||
timerObserver.OnCompleted();
|
||||
});
|
||||
}
|
||||
else
|
||||
|
||||
var periodicScheduler = scheduler as ISchedulerPeriodic;
|
||||
if (periodicScheduler != null)
|
||||
{
|
||||
var periodicScheduler = scheduler as ISchedulerPeriodic;
|
||||
if (periodicScheduler != null)
|
||||
if (dueTime == period.Value)
|
||||
// same(Observable.Interval), run periodic
|
||||
return periodicScheduler.SchedulePeriodic(Scheduler.Normalize(dueTime), timerObserver.OnNext);
|
||||
|
||||
// Schedule Once + Scheudle Periodic
|
||||
var disposable = new SerialDisposable();
|
||||
|
||||
disposable.Disposable = scheduler.Schedule(Scheduler.Normalize(dueTime), () =>
|
||||
{
|
||||
if (dueTime == period.Value)
|
||||
{
|
||||
// same(Observable.Interval), run periodic
|
||||
return periodicScheduler.SchedulePeriodic(Scheduler.Normalize(dueTime), timerObserver.OnNext);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Schedule Once + Scheudle Periodic
|
||||
var disposable = new SerialDisposable();
|
||||
timerObserver.OnNext(); // run first
|
||||
|
||||
disposable.Disposable = scheduler.Schedule(Scheduler.Normalize(dueTime), () =>
|
||||
{
|
||||
timerObserver.OnNext(); // run first
|
||||
|
||||
var timeP = Scheduler.Normalize(period.Value);
|
||||
disposable.Disposable = periodicScheduler.SchedulePeriodic(timeP, timerObserver.OnNext); // run periodic
|
||||
});
|
||||
|
||||
return disposable;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var timeP = Scheduler.Normalize(period.Value);
|
||||
disposable.Disposable =
|
||||
periodicScheduler.SchedulePeriodic(timeP, timerObserver.OnNext); // run periodic
|
||||
});
|
||||
|
||||
return scheduler.Schedule(Scheduler.Normalize(dueTime), self =>
|
||||
{
|
||||
timerObserver.OnNext();
|
||||
self(timeP);
|
||||
});
|
||||
}
|
||||
return disposable;
|
||||
}
|
||||
|
||||
{
|
||||
var timeP = Scheduler.Normalize(period.Value);
|
||||
|
||||
return scheduler.Schedule(Scheduler.Normalize(dueTime), self =>
|
||||
{
|
||||
timerObserver.OnNext();
|
||||
self(timeP);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class Timer : OperatorObserverBase<long, long>
|
||||
private class Timer : OperatorObserverBase<long, long>
|
||||
{
|
||||
long index = 0;
|
||||
private long index;
|
||||
|
||||
public Timer(IObserver<long> observer, IDisposable cancel)
|
||||
: base(observer, cancel)
|
||||
@@ -94,7 +87,7 @@ namespace UniRx.Operators
|
||||
{
|
||||
try
|
||||
{
|
||||
base.observer.OnNext(index++);
|
||||
observer.OnNext(index++);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -110,14 +103,26 @@ namespace UniRx.Operators
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
{
|
||||
try { observer.OnCompleted(); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,23 +7,14 @@ namespace UniRx
|
||||
[Serializable]
|
||||
public struct Pair<T> : IEquatable<Pair<T>>
|
||||
{
|
||||
readonly T previous;
|
||||
readonly T current;
|
||||
public T Previous { get; }
|
||||
|
||||
public T Previous
|
||||
{
|
||||
get { return previous; }
|
||||
}
|
||||
|
||||
public T Current
|
||||
{
|
||||
get { return current; }
|
||||
}
|
||||
public T Current { get; }
|
||||
|
||||
public Pair(T previous, T current)
|
||||
{
|
||||
this.previous = previous;
|
||||
this.current = current;
|
||||
this.Previous = previous;
|
||||
this.Current = current;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
@@ -31,8 +22,8 @@ namespace UniRx
|
||||
var comparer = EqualityComparer<T>.Default;
|
||||
|
||||
int h0;
|
||||
h0 = comparer.GetHashCode(previous);
|
||||
h0 = (h0 << 5) + h0 ^ comparer.GetHashCode(current);
|
||||
h0 = comparer.GetHashCode(Previous);
|
||||
h0 = ((h0 << 5) + h0) ^ comparer.GetHashCode(Current);
|
||||
return h0;
|
||||
}
|
||||
|
||||
@@ -47,13 +38,13 @@ namespace UniRx
|
||||
{
|
||||
var comparer = EqualityComparer<T>.Default;
|
||||
|
||||
return comparer.Equals(previous, other.Previous) &&
|
||||
comparer.Equals(current, other.Current);
|
||||
return comparer.Equals(Previous, other.Previous) &&
|
||||
comparer.Equals(Current, other.Current);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("({0}, {1})", previous, current);
|
||||
return string.Format("({0}, {1})", Previous, Current);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UniRx.InternalUtil;
|
||||
|
||||
namespace UniRx
|
||||
{
|
||||
public sealed class Subject<T> : ISubject<T>, IDisposable, IOptimizedObservable<T>
|
||||
{
|
||||
object observerLock = new object();
|
||||
private bool isDisposed;
|
||||
|
||||
bool isStopped;
|
||||
bool isDisposed;
|
||||
Exception lastError;
|
||||
IObserver<T> outObserver = EmptyObserver<T>.Instance;
|
||||
private bool isStopped;
|
||||
private Exception lastError;
|
||||
private readonly object observerLock = new();
|
||||
private IObserver<T> outObserver = EmptyObserver<T>.Instance;
|
||||
|
||||
public bool HasObservers
|
||||
public bool HasObservers => !(outObserver is EmptyObserver<T>) && !isStopped && !isDisposed;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
get
|
||||
lock (observerLock)
|
||||
{
|
||||
return !(outObserver is EmptyObserver<T>) && !isStopped && !isDisposed;
|
||||
isDisposed = true;
|
||||
outObserver = DisposedObserver<T>.Instance;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsRequiredSubscribeOnCurrentThread()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnCompleted()
|
||||
{
|
||||
IObserver<T> old;
|
||||
@@ -82,13 +88,10 @@ namespace UniRx
|
||||
{
|
||||
var current = outObserver;
|
||||
if (current is EmptyObserver<T>)
|
||||
{
|
||||
outObserver = observer;
|
||||
}
|
||||
else
|
||||
{
|
||||
outObserver = new ListObserver<T>(new ImmutableList<IObserver<T>>(new[] { current, observer }));
|
||||
}
|
||||
outObserver =
|
||||
new ListObserver<T>(new ImmutableList<IObserver<T>>(new[] { current, observer }));
|
||||
}
|
||||
|
||||
return new Subscription(this, observer);
|
||||
@@ -98,41 +101,23 @@ namespace UniRx
|
||||
}
|
||||
|
||||
if (ex != null)
|
||||
{
|
||||
observer.OnError(ex);
|
||||
}
|
||||
else
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
|
||||
return Disposable.Empty;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
lock (observerLock)
|
||||
{
|
||||
isDisposed = true;
|
||||
outObserver = DisposedObserver<T>.Instance;
|
||||
}
|
||||
}
|
||||
|
||||
void ThrowIfDisposed()
|
||||
private void ThrowIfDisposed()
|
||||
{
|
||||
if (isDisposed) throw new ObjectDisposedException("");
|
||||
}
|
||||
|
||||
public bool IsRequiredSubscribeOnCurrentThread()
|
||||
private class Subscription : IDisposable
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
class Subscription : IDisposable
|
||||
{
|
||||
readonly object gate = new object();
|
||||
Subject<T> parent;
|
||||
IObserver<T> unsubscribeTarget;
|
||||
private readonly object gate = new();
|
||||
private Subject<T> parent;
|
||||
private IObserver<T> unsubscribeTarget;
|
||||
|
||||
public Subscription(Subject<T> parent, IObserver<T> unsubscribeTarget)
|
||||
{
|
||||
@@ -145,23 +130,17 @@ namespace UniRx
|
||||
lock (gate)
|
||||
{
|
||||
if (parent != null)
|
||||
{
|
||||
lock (parent.observerLock)
|
||||
{
|
||||
var listObserver = parent.outObserver as ListObserver<T>;
|
||||
if (listObserver != null)
|
||||
{
|
||||
parent.outObserver = listObserver.Remove(unsubscribeTarget);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent.outObserver = EmptyObserver<T>.Instance;
|
||||
}
|
||||
|
||||
unsubscribeTarget = null;
|
||||
parent = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ namespace UniRx
|
||||
return new AnonymousSubject<T>((subject as IObserver<T>).Synchronize(gate), subject);
|
||||
}
|
||||
|
||||
class AnonymousSubject<T, U> : ISubject<T, U>
|
||||
private class AnonymousSubject<T, U> : ISubject<T, U>
|
||||
{
|
||||
readonly IObserver<T> observer;
|
||||
readonly IObservable<U> observable;
|
||||
private readonly IObservable<U> observable;
|
||||
private readonly IObserver<T> observer;
|
||||
|
||||
public AnonymousSubject(IObserver<T> observer, IObservable<U> observable)
|
||||
{
|
||||
@@ -50,7 +50,7 @@ namespace UniRx
|
||||
}
|
||||
}
|
||||
|
||||
class AnonymousSubject<T> : AnonymousSubject<T, T>, ISubject<T>
|
||||
private class AnonymousSubject<T> : AnonymousSubject<T, T>, ISubject<T>
|
||||
{
|
||||
public AnonymousSubject(IObserver<T> observer, IObservable<T> observable)
|
||||
: base(observer, observable)
|
||||
|
||||
@@ -11,45 +11,38 @@ using System.Globalization;
|
||||
namespace UniRx
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a value associated with time interval information.
|
||||
/// The time interval can represent the time it took to produce the value, the interval relative to a previous value, the value's delivery time relative to a base, etc.
|
||||
/// Represents a value associated with time interval information.
|
||||
/// The time interval can represent the time it took to produce the value, the interval relative to a previous value,
|
||||
/// the value's delivery time relative to a base, etc.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the value being annotated with time interval information.</typeparam>
|
||||
[Serializable]
|
||||
public struct TimeInterval<T> : IEquatable<TimeInterval<T>>
|
||||
{
|
||||
private readonly TimeSpan _interval;
|
||||
private readonly T _value;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a time interval value.
|
||||
/// Constructs a time interval value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to be annotated with a time interval.</param>
|
||||
/// <param name="interval">Time interval associated with the value.</param>
|
||||
public TimeInterval(T value, TimeSpan interval)
|
||||
{
|
||||
_interval = interval;
|
||||
_value = value;
|
||||
Interval = interval;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value.
|
||||
/// Gets the value.
|
||||
/// </summary>
|
||||
public T Value
|
||||
{
|
||||
get { return _value; }
|
||||
}
|
||||
public T Value { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the interval.
|
||||
/// Gets the interval.
|
||||
/// </summary>
|
||||
public TimeSpan Interval
|
||||
{
|
||||
get { return _interval; }
|
||||
}
|
||||
public TimeSpan Interval { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the current TimeInterval<T> value has the same Value and Interval as a specified TimeInterval<T> value.
|
||||
/// Determines whether the current TimeInterval<T> value has the same Value and Interval as a specified
|
||||
/// TimeInterval<T> value.
|
||||
/// </summary>
|
||||
/// <param name="other">An object to compare to the current TimeInterval<T> value.</param>
|
||||
/// <returns>true if both TimeInterval<T> values have the same Value and Interval; otherwise, false.</returns>
|
||||
@@ -59,29 +52,35 @@ namespace UniRx
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the two specified TimeInterval<T> values have the same Value and Interval.
|
||||
/// Determines whether the two specified TimeInterval<T> values have the same Value and Interval.
|
||||
/// </summary>
|
||||
/// <param name="first">The first TimeInterval<T> value to compare.</param>
|
||||
/// <param name="second">The second TimeInterval<T> value to compare.</param>
|
||||
/// <returns>true if the first TimeInterval<T> value has the same Value and Interval as the second TimeInterval<T> value; otherwise, false.</returns>
|
||||
/// <returns>
|
||||
/// true if the first TimeInterval<T> value has the same Value and Interval as the second TimeInterval<T
|
||||
/// > value; otherwise, false.
|
||||
/// </returns>
|
||||
public static bool operator ==(TimeInterval<T> first, TimeInterval<T> second)
|
||||
{
|
||||
return first.Equals(second);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the two specified TimeInterval<T> values don't have the same Value and Interval.
|
||||
/// Determines whether the two specified TimeInterval<T> values don't have the same Value and Interval.
|
||||
/// </summary>
|
||||
/// <param name="first">The first TimeInterval<T> value to compare.</param>
|
||||
/// <param name="second">The second TimeInterval<T> value to compare.</param>
|
||||
/// <returns>true if the first TimeInterval<T> value has a different Value or Interval as the second TimeInterval<T> value; otherwise, false.</returns>
|
||||
/// <returns>
|
||||
/// true if the first TimeInterval<T> value has a different Value or Interval as the second TimeInterval<
|
||||
/// T> value; otherwise, false.
|
||||
/// </returns>
|
||||
public static bool operator !=(TimeInterval<T> first, TimeInterval<T> second)
|
||||
{
|
||||
return !first.Equals(second);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified System.Object is equal to the current TimeInterval<T>.
|
||||
/// Determines whether the specified System.Object is equal to the current TimeInterval<T>.
|
||||
/// </summary>
|
||||
/// <param name="obj">The System.Object to compare with the current TimeInterval<T>.</param>
|
||||
/// <returns>true if the specified System.Object is equal to the current TimeInterval<T>; otherwise, false.</returns>
|
||||
@@ -91,11 +90,11 @@ namespace UniRx
|
||||
return false;
|
||||
|
||||
var other = (TimeInterval<T>)obj;
|
||||
return this.Equals(other);
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hash code for the current TimeInterval<T> value.
|
||||
/// Returns the hash code for the current TimeInterval<T> value.
|
||||
/// </summary>
|
||||
/// <returns>A hash code for the current TimeInterval<T> value.</returns>
|
||||
public override int GetHashCode()
|
||||
@@ -106,12 +105,12 @@ namespace UniRx
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representation of the current TimeInterval<T> value.
|
||||
/// Returns a string representation of the current TimeInterval<T> value.
|
||||
/// </summary>
|
||||
/// <returns>String representation of the current TimeInterval<T> value.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format(CultureInfo.CurrentCulture, "{0}@{1}", Value, Interval);
|
||||
return string.Format(CultureInfo.CurrentCulture, "{0}@{1}", Value, Interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "UniRx",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
"name": "UniRx",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
}
|
||||
@@ -19,10 +19,7 @@ namespace UniRx
|
||||
}
|
||||
|
||||
var trigger = gameObject.GetComponent<ObservableDestroyTrigger>();
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger = gameObject.AddComponent<ObservableDestroyTrigger>();
|
||||
}
|
||||
if (trigger == null) trigger = gameObject.AddComponent<ObservableDestroyTrigger>();
|
||||
|
||||
#pragma warning disable 618
|
||||
|
||||
@@ -39,7 +36,7 @@ namespace UniRx
|
||||
return disposable;
|
||||
}
|
||||
|
||||
static IEnumerator MonitorTriggerHealth(ObservableDestroyTrigger trigger, GameObject targetGameObject)
|
||||
private static IEnumerator MonitorTriggerHealth(ObservableDestroyTrigger trigger, GameObject targetGameObject)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
@@ -64,12 +61,15 @@ namespace UniRx
|
||||
return disposable;
|
||||
}
|
||||
|
||||
return AddTo(disposable, gameObjectComponent.gameObject);
|
||||
return disposable.AddTo(gameObjectComponent.gameObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Add disposable(self) to CompositeDisposable(or other ICollection) and Dispose self on target gameObject has been destroyed.</para>
|
||||
/// <para>Return value is self disposable.</para>
|
||||
/// <para>
|
||||
/// Add disposable(self) to CompositeDisposable(or other ICollection) and Dispose self on target gameObject has
|
||||
/// been destroyed.
|
||||
/// </para>
|
||||
/// <para>Return value is self disposable.</para>
|
||||
/// </summary>
|
||||
public static T AddTo<T>(this T disposable, ICollection<IDisposable> container, GameObject gameObject)
|
||||
where T : IDisposable
|
||||
@@ -78,8 +78,11 @@ namespace UniRx
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Add disposable(self) to CompositeDisposable(or other ICollection) and Dispose self on target gameObject has been destroyed.</para>
|
||||
/// <para>Return value is self disposable.</para>
|
||||
/// <para>
|
||||
/// Add disposable(self) to CompositeDisposable(or other ICollection) and Dispose self on target gameObject has
|
||||
/// been destroyed.
|
||||
/// </para>
|
||||
/// <para>Return value is self disposable.</para>
|
||||
/// </summary>
|
||||
public static T AddTo<T>(this T disposable, ICollection<IDisposable> container, Component gameObjectComponent)
|
||||
where T : IDisposable
|
||||
|
||||
@@ -7,11 +7,12 @@ namespace UniRx.Operators
|
||||
{
|
||||
internal class RepeatUntilObservable<T> : OperatorObservableBase<T>
|
||||
{
|
||||
readonly IEnumerable<IObservable<T>> sources;
|
||||
readonly IObservable<Unit> trigger;
|
||||
readonly GameObject lifeTimeChecker;
|
||||
private readonly GameObject lifeTimeChecker;
|
||||
private readonly IEnumerable<IObservable<T>> sources;
|
||||
private readonly IObservable<Unit> trigger;
|
||||
|
||||
public RepeatUntilObservable(IEnumerable<IObservable<T>> sources, IObservable<Unit> trigger, GameObject lifeTimeChecker)
|
||||
public RepeatUntilObservable(IEnumerable<IObservable<T>> sources, IObservable<Unit> trigger,
|
||||
GameObject lifeTimeChecker)
|
||||
: base(true)
|
||||
{
|
||||
this.sources = sources;
|
||||
@@ -24,21 +25,22 @@ namespace UniRx.Operators
|
||||
return new RepeatUntil(this, observer, cancel).Run();
|
||||
}
|
||||
|
||||
class RepeatUntil : OperatorObserverBase<T, T>
|
||||
private class RepeatUntil : OperatorObserverBase<T, T>
|
||||
{
|
||||
readonly RepeatUntilObservable<T> parent;
|
||||
readonly object gate = new object();
|
||||
private readonly object gate = new();
|
||||
private readonly RepeatUntilObservable<T> parent;
|
||||
|
||||
IEnumerator<IObservable<T>> e;
|
||||
SerialDisposable subscription;
|
||||
SingleAssignmentDisposable schedule;
|
||||
Action nextSelf;
|
||||
bool isStopped;
|
||||
bool isDisposed;
|
||||
bool isFirstSubscribe;
|
||||
IDisposable stopper;
|
||||
private IEnumerator<IObservable<T>> e;
|
||||
private bool isDisposed;
|
||||
private bool isFirstSubscribe;
|
||||
private bool isStopped;
|
||||
private Action nextSelf;
|
||||
private SingleAssignmentDisposable schedule;
|
||||
private IDisposable stopper;
|
||||
private SerialDisposable subscription;
|
||||
|
||||
public RepeatUntil(RepeatUntilObservable<T> parent, IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
|
||||
public RepeatUntil(RepeatUntilObservable<T> parent, IObserver<T> observer, IDisposable cancel) : base(
|
||||
observer, cancel)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
@@ -76,11 +78,11 @@ namespace UniRx.Operators
|
||||
}));
|
||||
}
|
||||
|
||||
void RecursiveRun(Action self)
|
||||
private void RecursiveRun(Action self)
|
||||
{
|
||||
lock (gate)
|
||||
{
|
||||
this.nextSelf = self;
|
||||
nextSelf = self;
|
||||
if (isDisposed) return;
|
||||
if (isStopped) return;
|
||||
|
||||
@@ -132,45 +134,54 @@ namespace UniRx.Operators
|
||||
}
|
||||
else
|
||||
{
|
||||
MainThreadDispatcher.SendStartCoroutine(SubscribeAfterEndOfFrame(d, source, this, parent.lifeTimeChecker));
|
||||
MainThreadDispatcher.SendStartCoroutine(SubscribeAfterEndOfFrame(d, source, this,
|
||||
parent.lifeTimeChecker));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static IEnumerator SubscribeAfterEndOfFrame(SingleAssignmentDisposable d, IObservable<T> source, IObserver<T> observer, GameObject lifeTimeChecker)
|
||||
private static IEnumerator SubscribeAfterEndOfFrame(SingleAssignmentDisposable d, IObservable<T> source,
|
||||
IObserver<T> observer, GameObject lifeTimeChecker)
|
||||
{
|
||||
yield return YieldInstructionCache.WaitForEndOfFrame;
|
||||
if (!d.IsDisposed && lifeTimeChecker != null)
|
||||
{
|
||||
d.Disposable = source.Subscribe(observer);
|
||||
}
|
||||
if (!d.IsDisposed && lifeTimeChecker != null) d.Disposable = source.Subscribe(observer);
|
||||
}
|
||||
|
||||
public override void OnNext(T value)
|
||||
{
|
||||
base.observer.OnNext(value);
|
||||
observer.OnNext(value);
|
||||
}
|
||||
|
||||
public override void OnError(Exception error)
|
||||
{
|
||||
try { observer.OnError(error); }
|
||||
finally { Dispose(); }
|
||||
try
|
||||
{
|
||||
observer.OnError(error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
{
|
||||
if (!isDisposed)
|
||||
{
|
||||
this.nextSelf();
|
||||
nextSelf();
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Dispose();
|
||||
if (!isDisposed)
|
||||
{
|
||||
try { observer.OnCompleted(); }
|
||||
finally { Dispose(); }
|
||||
}
|
||||
try
|
||||
{
|
||||
observer.OnCompleted();
|
||||
}
|
||||
finally
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
using System; // require keep for Windows Universal App
|
||||
using System;
|
||||
using UnityEngine;
|
||||
// require keep for Windows Universal App
|
||||
|
||||
namespace UniRx.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class ObservableEnableTrigger : ObservableTriggerBase
|
||||
{
|
||||
Subject<Unit> onEnable;
|
||||
private Subject<Unit> onDisable;
|
||||
private Subject<Unit> onEnable;
|
||||
|
||||
/// <summary>This function is called when the object becomes enabled and active.</summary>
|
||||
void OnEnable()
|
||||
private void OnEnable()
|
||||
{
|
||||
if (onEnable != null) onEnable.OnNext(Unit.Default);
|
||||
}
|
||||
|
||||
/// <summary>This function is called when the behaviour becomes disabled () or inactive.</summary>
|
||||
private void OnDisable()
|
||||
{
|
||||
if (onDisable != null) onDisable.OnNext(Unit.Default);
|
||||
}
|
||||
|
||||
/// <summary>This function is called when the object becomes enabled and active.</summary>
|
||||
public IObservable<Unit> OnEnableAsObservable()
|
||||
{
|
||||
return onEnable ?? (onEnable = new Subject<Unit>());
|
||||
}
|
||||
|
||||
Subject<Unit> onDisable;
|
||||
|
||||
/// <summary>This function is called when the behaviour becomes disabled () or inactive.</summary>
|
||||
void OnDisable()
|
||||
{
|
||||
if (onDisable != null) onDisable.OnNext(Unit.Default);
|
||||
}
|
||||
|
||||
/// <summary>This function is called when the behaviour becomes disabled () or inactive.</summary>
|
||||
public IObservable<Unit> OnDisableAsObservable()
|
||||
{
|
||||
@@ -36,14 +36,8 @@ namespace UniRx.Triggers
|
||||
|
||||
protected override void RaiseOnCompletedOnDestroy()
|
||||
{
|
||||
if (onEnable != null)
|
||||
{
|
||||
onEnable.OnCompleted();
|
||||
}
|
||||
if (onDisable != null)
|
||||
{
|
||||
onDisable.OnCompleted();
|
||||
}
|
||||
if (onEnable != null) onEnable.OnCompleted();
|
||||
if (onDisable != null) onDisable.OnCompleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,18 @@
|
||||
// for uGUI(from 4.6)
|
||||
|
||||
#if !(UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
|
||||
|
||||
using System; // require keep for Windows Universal App
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
// require keep for Windows Universal App
|
||||
|
||||
namespace UniRx.Triggers
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class ObservablePointerDownTrigger : ObservableTriggerBase, IEventSystemHandler, IPointerDownHandler
|
||||
{
|
||||
Subject<PointerEventData> onPointerDown;
|
||||
private Subject<PointerEventData> onPointerDown;
|
||||
|
||||
void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
@@ -24,10 +26,7 @@ namespace UniRx.Triggers
|
||||
|
||||
protected override void RaiseOnCompletedOnDestroy()
|
||||
{
|
||||
if (onPointerDown != null)
|
||||
{
|
||||
onPointerDown.OnCompleted();
|
||||
}
|
||||
if (onPointerDown != null) onPointerDown.OnCompleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// after uGUI(from 4.6)
|
||||
|
||||
#if !(UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
|
||||
|
||||
using System;
|
||||
@@ -9,10 +10,12 @@ namespace UniRx.Triggers
|
||||
[DisallowMultipleComponent]
|
||||
public class ObservableRectTransformTrigger : ObservableTriggerBase
|
||||
{
|
||||
Subject<Unit> onRectTransformDimensionsChange;
|
||||
private Subject<Unit> onRectTransformDimensionsChange;
|
||||
|
||||
private Subject<Unit> onRectTransformRemoved;
|
||||
|
||||
// Callback that is sent if an associated RectTransform has it's dimensions changed
|
||||
void OnRectTransformDimensionsChange()
|
||||
private void OnRectTransformDimensionsChange()
|
||||
{
|
||||
if (onRectTransformDimensionsChange != null) onRectTransformDimensionsChange.OnNext(Unit.Default);
|
||||
}
|
||||
@@ -23,10 +26,8 @@ namespace UniRx.Triggers
|
||||
return onRectTransformDimensionsChange ?? (onRectTransformDimensionsChange = new Subject<Unit>());
|
||||
}
|
||||
|
||||
Subject<Unit> onRectTransformRemoved;
|
||||
|
||||
// Callback that is sent if an associated RectTransform is removed
|
||||
void OnRectTransformRemoved()
|
||||
private void OnRectTransformRemoved()
|
||||
{
|
||||
if (onRectTransformRemoved != null) onRectTransformRemoved.OnNext(Unit.Default);
|
||||
}
|
||||
@@ -39,16 +40,9 @@ namespace UniRx.Triggers
|
||||
|
||||
protected override void RaiseOnCompletedOnDestroy()
|
||||
{
|
||||
if (onRectTransformDimensionsChange != null)
|
||||
{
|
||||
onRectTransformDimensionsChange.OnCompleted();
|
||||
}
|
||||
if (onRectTransformRemoved != null)
|
||||
{
|
||||
onRectTransformRemoved.OnCompleted();
|
||||
}
|
||||
if (onRectTransformDimensionsChange != null) onRectTransformDimensionsChange.OnCompleted();
|
||||
if (onRectTransformRemoved != null) onRectTransformRemoved.OnCompleted();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#if UNITY_METRO
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
Reference in New Issue
Block a user