これは説明するのは難しい1、コードを初めて目のビットです:観察可能なヌルと価値観察可能な事実ではない
public static IObservable<bool> NotNullAnd<T>(IReadOnlyReactiveProperty<T> prop,
Func<T, IObservable<bool>> andSelector)
{
var notNull = prop.Select(l => l != null);
var isExecuting = prop
.Where(l => l != null)
.SelectMany(l => andSelector(l));
return notNull.CombineLatest(isExecuting, (x, y) => x && y);
}
このコードが動作するようですが、これはするための最良の方法である場合イムわかりませんこれを行う。
基本的には、オブジェクト上のオブザーバブルがトリガーされたときにそのオブジェクトがnullになる可能性があるかどうかを調べる方法を探しています。だから、組み合わせが説明するのは難しいが、おそらくテストは説明するのに役立つかもしれないし、オブジェクトの別のプロパティのために聴くとプロパティの変更、そうでない場合はnullのチェック...です:
private class Loader
{
public ReactiveProperty<bool> IsExecuting
= new ReactiveProperty<bool>();
}
[Test]
public void TestNotNullAnd()
{
var loaderProp = new ReactiveProperty<Loader>();
var isExecutingProp = NotNullAnd(loaderProp, l => l.IsExecuting)
.ToReadOnlyReactiveProperty();
var loader = new Loader();
Assert.IsFalse(isExecutingProp.Value);
loaderProp.Value = loader;
Assert.IsFalse(isExecutingProp.Value);
loaderProp.Value.IsExecuting.Value = true;
Assert.IsTrue(isExecutingProp.Value);
loaderProp.Value.IsExecuting.Value = false;
Assert.IsFalse(isExecutingProp.Value);
loaderProp.Value.IsExecuting.Value = true;
Assert.IsTrue(isExecutingProp.Value);
loaderProp.Value.IsExecuting.Value = false;
Assert.IsFalse(isExecutingProp.Value);
loaderProp.Value.IsExecuting.Value = true;
Assert.IsTrue(isExecutingProp.Value);
loaderProp.Value = null;
Assert.IsFalse(isExecutingProp.Value);
loaderProp.Value = loader;
Assert.IsTrue(isExecutingProp.Value);
}
を述べたように、これらすべてのテストに合格しますしかし、もっと良い方法があるかどうかはっきりしていません。さらに、 "l.IsExecuting"を聞いていないので、ここにメモリリークを導入することを心配しています。
Im "UniRx" libary Unityのために。
申し訳ありませんが、このdoesntの仕事..あなたがテストを実行する場合は、最後のアサートからの第二は、 '' loaderProp.Value = nullを '失敗しました。 Assert.IsFalse(isExecutingProp.Value); '' ' – mikeysee
@mikeysee回答が修正されました!私は最初の行為についてあなたの意図を誤解しました。 – concat
素敵な仕事!すべてのテストが合格し、あなたの助けを借りて、大変お世話になりました! – mikeysee